Mantid
Loading...
Searching...
No Matches
Peak.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
15
16#include "boost/make_shared.hpp"
17
18#include <algorithm>
19#include <cctype>
20#include <string>
21#include <utility>
22
23using namespace Mantid;
24using namespace Mantid::Kernel;
25using namespace Mantid::Geometry;
26
27namespace Mantid::DataObjects {
28
29//----------------------------------------------------------------------------------------------
31Peak::Peak() : BasePeak(), m_row(-1), m_col(-1), m_detectorID(-1), m_initialEnergy(0.), m_finalEnergy(0.) {}
32
33//----------------------------------------------------------------------------------------------
44 boost::optional<double> detectorDistance)
45 : BasePeak() {
46 // Initialization of m_inst, sourcePos, m_samplePos
48 // Initialization of m_detectorID, detPos, m_det, m_row, m_col, m_bankName, m_initialEnergy, m_finalEnergy
49 setQLabFrame(QLabFrame, std::move(detectorDistance));
50}
51
52//----------------------------------------------------------------------------------------------
66 const Mantid::Kernel::Matrix<double> &goniometer, boost::optional<double> detectorDistance)
67 : BasePeak(goniometer) {
68 // Initialization of m_inst, sourcePos, m_samplePos
69 this->setInstrument(m_inst);
70 // Initialization of m_detectorID, detPos, m_det, m_row, m_col, m_bankName, m_initialEnergy, m_finalEnergy
71 this->setQSampleFrame(QSampleFrame, std::move(detectorDistance));
72}
73
74//----------------------------------------------------------------------------------------------
82Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID, double m_Wavelength) : BasePeak() {
83 // Initialization of m_inst, sourcePos, m_samplePos
84 this->setInstrument(m_inst);
85 // Initialization of m_detectorID, detPos, m_det, m_row, m_col, m_bankName
86 this->setDetectorID(m_detectorID);
87 // Initialization of m_initialEnergy, m_finalEnergy
88 this->setWavelength(m_Wavelength);
89}
90
91//----------------------------------------------------------------------------------------------
100Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID, double m_Wavelength,
102 : BasePeak() {
103 // Initialization of m_inst, sourcePos, m_samplePos
104 this->setInstrument(m_inst);
105 // Initialization of m_detectorID, detPos, m_det, m_row, m_col, m_bankName
106 this->setDetectorID(m_detectorID);
107 // Initialization of m_initialEnergy, m_finalEnergy
108 this->setWavelength(m_Wavelength);
109 this->setHKL(HKL);
110}
111
112//----------------------------------------------------------------------------------------------
122Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID, double m_Wavelength,
124 : BasePeak(goniometer) {
125 // Initialization of m_inst, sourcePos, m_samplePos
126 this->setInstrument(m_inst);
127 // Initialization of m_detectorID, detPos, m_det, m_row, m_col, m_bankName
128 this->setDetectorID(m_detectorID);
129 // Initialization of m_initialEnergy, m_finalEnergy
130 this->setWavelength(m_Wavelength);
131 this->setHKL(HKL);
132}
133
134//----------------------------------------------------------------------------------------------
142Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, double scattering, double m_Wavelength)
143 : BasePeak(), m_row(-1), m_col(-1) {
144 // Initialization of m_inst, sourcePos, m_samplePos
145 this->setInstrument(m_inst);
146 // Initialization of m_initialEnergy, m_finalEnergy
147 this->setWavelength(m_Wavelength);
148 m_detectorID = -1;
149 // get the approximate location of the detector
150 const auto detectorDir = V3D(sin(scattering), 0.0, cos(scattering));
151 detPos = getVirtualDetectorPosition(detectorDir);
152}
153
159Peak::Peak(const Peak &other) = default;
160
161//----------------------------------------------------------------------------------------------
169 : BasePeak(ipeak), m_initialEnergy(ipeak.getInitialEnergy()), m_finalEnergy(ipeak.getFinalEnergy()) {
170 const auto *peak = dynamic_cast<const Peak *>(&ipeak);
171 if (!peak)
172 throw std::invalid_argument("Cannot construct a Peak from this non-Peak object");
173 setInstrument(peak->getInstrument());
174 detid_t id = peak->getDetectorID();
175 if (id >= 0)
176 setDetectorID(id);
177 this->m_detIDs = peak->m_detIDs;
178}
179
180//----------------------------------------------------------------------------------------------
182 boost::optional<double> detectorDistance)
183 : BasePeak(lpeak) {
184 this->setInstrument(inst);
185 this->setQLabFrame(lpeak.getQLabFrame(), std::move(detectorDistance));
186}
187
188//----------------------------------------------------------------------------------------------
194void Peak::setWavelength(double wavelength) {
195 // Velocity of the neutron (non-relativistic)
196 double velocity = PhysicalConstants::h / (wavelength * 1e-10 * PhysicalConstants::NeutronMass);
197 // Energy in J of the neutron
198 double energy = PhysicalConstants::NeutronMass * velocity * velocity / 2.0;
199 // Convert to meV
202}
203
204//----------------------------------------------------------------------------------------------
213 if (!m_inst)
214 throw std::runtime_error("Peak::setInstrument(): No instrument is set!");
215 this->m_det = m_inst->getDetector(id);
216 if (!m_det)
217 throw std::runtime_error("Peak::setInstrument(): No detector was found!");
218
219 this->m_detectorID = id;
221
222 detPos = m_det->getPos();
223
224 // We now look for the row/column. -1 if not found.
225 setRow(-1);
226 setCol(-1);
227
228 // Go up 2 parents to find the bank/rectangular detector
229 IComponent_const_sptr parent = m_det->getParent();
230
231 // Find the ROW by looking at the string name of the pixel. E.g. "pixel12"
232 // gives row 12.
233 setRow(Strings::endsWithInt(m_det->getName()));
234
235 if (!parent)
236 return;
237 setBankName(parent->getName());
238
239 // Find the COLUMN by looking at the string name of the parent. E.g. "tube003"
240 // gives column 3.
241 setCol(Strings::endsWithInt(parent->getName()));
242
243 parent = parent->getParent();
244 // Use the parent if there is no grandparent.
245 if (!parent)
246 return;
247
248 // Use the parent if the grandparent is the instrument
249 Instrument_const_sptr instrument = std::dynamic_pointer_cast<const Instrument>(parent);
250 if (instrument)
251 return;
252 // Use the grand-parent whenever possible
253 setBankName(parent->getName());
254 // For CORELLI, one level above sixteenpack
255 if (getBankName() == "sixteenpack") {
256 parent = parent->getParent();
257 setBankName(parent->getName());
258 }
259
260 // Special for rectangular detectors: find the row and column.
261 RectangularDetector_const_sptr retDet = std::dynamic_pointer_cast<const RectangularDetector>(parent);
262 if (!retDet)
263 return;
264 std::pair<int, int> xy = retDet->getXYForDetectorID(m_detectorID);
265 setRow(xy.second);
266 setCol(xy.first);
267}
268
269//----------------------------------------------------------------------------------------------
271int Peak::getDetectorID() const { return m_detectorID; }
272
273//----------------------------------------------------------------------------------------------
278void Peak::addContributingDetID(const int id) { m_detIDs.insert(id); }
279
280//-------------------------------------------------------------------------------------
285void Peak::removeContributingDetector(const int id) { m_detIDs.erase(id); }
286
287//----------------------------------------------------------------------------------------------
292const std::set<int> &Peak::getContributingDetIDs() const { return m_detIDs; }
293
294//----------------------------------------------------------------------------------------------
301 m_inst = inst;
302 if (!inst)
303 throw std::runtime_error("Peak::setInstrument(): No instrument is set!");
304
305 // Cache some positions
306 const Geometry::IComponent_const_sptr sourceObj = m_inst->getSource();
307 if (sourceObj == nullptr)
308 throw Exception::InstrumentDefinitionError("Peak::setInstrument(): Failed "
309 "to get source component from "
310 "instrument");
311 const Geometry::IComponent_const_sptr sampleObj = m_inst->getSample();
312 if (sampleObj == nullptr)
313 throw Exception::InstrumentDefinitionError("Peak::setInstrument(): Failed "
314 "to get sample component from "
315 "instrument");
316
317 sourcePos = sourceObj->getPos();
318 m_samplePos = sampleObj->getPos();
319}
320
321//----------------------------------------------------------------------------------------------
324
327
329std::shared_ptr<const Geometry::ReferenceFrame> Peak::getReferenceFrame() const { return m_inst->getReferenceFrame(); }
330
332int Peak::getRow() const { return m_row; }
333
338void Peak::setRow(int row) { m_row = row; }
339
341int Peak::getCol() const { return m_col; }
342
347void Peak::setCol(int col) { m_col = col; }
348
353std::string Peak::getBankName() const { return m_bankName; }
354
358void Peak::setBankName(std::string bankName) { this->m_bankName = std::move(bankName); }
359
360// -------------------------------------------------------------------------------------
364double Peak::getWavelength() const {
365 // Energy in J of the neutron
367 // v = sqrt(2.0 * E / m)
368 double velocity = sqrt(2.0 * energy / PhysicalConstants::NeutronMass);
369 // wavelength = h / mv
370 double wavelength = PhysicalConstants::h / (PhysicalConstants::NeutronMass * velocity);
371 // Return it in angstroms
372 return wavelength * 1e10;
373}
374
375// -------------------------------------------------------------------------------------
379double Peak::getTOF() const {
380 // First, get the neutron traveling distances
381 double L1 = this->getL1();
382 double L2 = this->getL2();
383 // Energy in J of the neutron
386 // v = sqrt(2 * E / m)
387 double vi = sqrt(2.0 * Ei / PhysicalConstants::NeutronMass);
388 double vf = sqrt(2.0 * Ef / PhysicalConstants::NeutronMass);
389 // Time of flight in seconds = distance / speed
390 double tof = L1 / vi + L2 / vf;
391 // Return in microsecond units
392 return tof * 1e6;
393}
394
395// -------------------------------------------------------------------------------------
397double Peak::getScattering() const {
398 // The detector is at 2 theta scattering angle
399 V3D beamDir = m_samplePos - sourcePos;
400 V3D detDir = detPos - m_samplePos;
401
402 return detDir.angle(beamDir);
403}
404
405// -------------------------------------------------------------------------------------
407double Peak::getAzimuthal() const {
408 // The detector is at 2 theta scattering angle
409 V3D detDir = detPos - m_samplePos;
410
411 return atan2(detDir.Y(), detDir.X());
412}
413
414// -------------------------------------------------------------------------------------
416double Peak::getDSpacing() const {
417 // The detector is at 2 theta scattering angle
418 V3D beamDir = m_samplePos - sourcePos;
419 V3D detDir = detPos - m_samplePos;
420
421 double two_theta;
422 try {
423 two_theta = detDir.angle(beamDir);
424 } catch (std::runtime_error &) {
425 two_theta = 0.;
426 }
427
428 // In general case (2*pi/d)^2=k_i^2+k_f^2-2*k_i*k_f*cos(two_theta)
429 // E_i,f=k_i,f^2*hbar^2/(2 m)
432 2.0 * sqrt(getInitialEnergy() * getFinalEnergy()) * cos(two_theta));
433}
434
435//----------------------------------------------------------------------------------------------
442 // Normalized beam direction
443 V3D beamDir = m_samplePos - sourcePos;
444 beamDir /= beamDir.norm();
445 // Normalized detector direction
446 V3D detDir = (detPos - m_samplePos);
447 detDir /= detDir.norm();
448
449 // Energy in J of the neutron
451 // v = sqrt(2.0 * E / m)
452 double vi = sqrt(2.0 * ei / PhysicalConstants::NeutronMass);
453 // wavenumber = h_bar / mv
455 // in angstroms
456 wi *= 1e10;
457 // wavevector=1/wavenumber = 2pi/wavelength
458 double wvi = 1.0 / wi;
459 // Now calculate the wavevector of the scattered neutron
460 double wvf = (2.0 * M_PI) / this->getWavelength();
461 // And Q in the lab frame
462 // Default for ki-kf is positive
463 double qSign = 1.0;
464 if (m_convention == "Crystallography")
465 qSign = -1.0;
466 return (beamDir * wvi - detDir * wvf) * qSign;
467}
468
469//----------------------------------------------------------------------------------------------
473 V3D Qlab = this->getQLabFrame();
474 // Multiply by the inverse of the goniometer matrix to get the sample frame
475 V3D Qsample = getInverseGoniometerMatrix() * Qlab;
476 return Qsample;
477}
478
479//----------------------------------------------------------------------------------------------
492void Peak::setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame, boost::optional<double> detectorDistance) {
493 V3D Qlab = getGoniometerMatrix() * QSampleFrame;
494 this->setQLabFrame(Qlab, detectorDistance);
495}
496
497//----------------------------------------------------------------------------------------------
513void Peak::setQLabFrame(const Mantid::Kernel::V3D &qLab, boost::optional<double> detectorDistance) {
514 if (!this->m_inst) {
515 throw std::invalid_argument("Setting QLab without an instrument would lead "
516 "to an inconsistent state for the Peak");
517 }
518 // Clear out the detector = we can't know them
519 m_detectorID = -1;
520 detPos = V3D();
522 m_row = -1;
523 m_col = -1;
524 setBankName("None");
525
526 /* The q-vector direction of the peak is = goniometer * ub * hkl_vector
527 * The incident neutron wavevector is along the beam direction, ki = 1/wl
528 * (usually z, but referenceframe is definitive).
529 * In the inelastic convention, q = ki - kf.
530 * The final neutron wavector kf = -qx in x; -qy in y; and (-q.beam_dir+1/wl)
531 * in beam direction.
532 * AND: norm(kf) = norm(ki) = 2*pi/wavelength
533 * THEREFORE: 1/wl = norm(q)^2 / (2*q.beam_dir)
534 */
535 const double norm_q = qLab.norm();
536 if (norm_q == 0.0)
537 throw std::invalid_argument("Peak::setQLabFrame(): Q cannot be 0,0,0.");
538
539 std::shared_ptr<const ReferenceFrame> refFrame = this->m_inst->getReferenceFrame();
540 const V3D refBeamDir = refFrame->vecPointingAlongBeam();
541 // Default for ki-kf has -q
542 const double qSign = (m_convention != "Crystallography") ? 1.0 : -1.0;
543 const double qBeam = qLab.scalar_prod(refBeamDir) * qSign;
544
545 if (qBeam == 0.0)
546 throw std::invalid_argument("Peak::setQLabFrame(): Q cannot be 0 in the beam direction.");
547
548 const double one_over_wl = (norm_q * norm_q) / (2.0 * qBeam);
549 const double wl = (2.0 * M_PI) / one_over_wl;
550 if (wl < 0.0) {
551 std::ostringstream mess;
552 mess << "Peak::setQLabFrame(): Wavelength found was negative (" << wl << " Ang)! This Q is not physical.";
553 throw std::invalid_argument(mess.str());
554 }
555
556 // Save the wavelength
557 this->setWavelength(wl);
558
559 V3D detectorDir = -qLab * qSign;
560 detectorDir[refFrame->pointingAlongBeam()] = one_over_wl - qBeam;
561 detectorDir.normalize();
562
563 // Use the given detector distance to find the detector position.
564 if (detectorDistance.is_initialized()) {
565 detPos = m_samplePos + detectorDir * detectorDistance.get();
566 // We do not-update the detector as by manually setting the distance the
567 // client seems to know better.
568 } else {
569 // Find the detector
571 const bool found = findDetector(detectorDir, tracer);
572 if (!found) {
573 // This is important, so we ought to log when this fails to happen.
574 g_log.debug("Could not find detector after setting qLab via setQLab with "
575 "QLab : " +
576 qLab.toString());
577
578 detPos = getVirtualDetectorPosition(detectorDir);
579 }
580 }
581}
582
583V3D Peak::getVirtualDetectorPosition(const V3D &detectorDir) const {
584 const auto component = getInstrument()->getComponentByName("extended-detector-space");
585 if (!component) {
586 return detectorDir; // the best idea we have is just the direction
587 }
588 const auto object = std::dynamic_pointer_cast<const ObjComponent>(component);
589 const auto distance = object->shape()->distance(Geometry::Track(m_samplePos, detectorDir));
590 return detectorDir * distance;
591}
592
593double Peak::getValueByColName(std::string name) const {
594 std::transform(name.begin(), name.end(), name.begin(), ::tolower);
595 std::map<std::string, double> colVals = {
596 {"detid", double(m_detectorID)}, {"row", double(m_row)}, {"col", double(m_col)}};
597 auto it = colVals.find(name);
598 if (it != colVals.end())
599 return it->second;
600 else
601 return BasePeak::getValueByColName(name);
602}
603
615 return findDetector(tracer);
616}
617
627 // Scattered beam direction
628 const V3D beam = normalize(detPos - m_samplePos);
629
630 return findDetector(beam, tracer);
631}
632
641 bool found = false;
642 // Create a ray tracer
643 tracer.traceFromSample(beam);
645 if (det) {
646 // Set the detector ID, the row, col, etc.
647 this->setDetectorID(det->getID());
648 // The old detector position is not more precise if it comes from
649 // FindPeaksMD
650 detPos = det->getPos();
651 found = true;
652 }
653 // Use tube-gap parameter in instrument parameter file to find peaks with
654 // center in gaps between tubes
655 else if (m_inst->hasParameter("tube-gap")) {
656 std::vector<double> gaps = m_inst->getNumberParameter("tube-gap", true);
657 if (!gaps.empty()) {
658 const auto gap = static_cast<double>(gaps.front());
659 // try adding and subtracting tube-gap in 3 q dimensions to see if you can
660 // find detectors on each side of tube gap
661 for (int i = 0; i < 3; i++) {
662 V3D gapDir;
663 gapDir[i] = gap;
664 V3D beam1 = beam + gapDir;
665 tracer.traceFromSample(normalize(beam1));
667 V3D beam2 = beam - gapDir;
668 tracer.traceFromSample(normalize(beam2));
670 if (det1 && det2) {
671 // compute the cosAngle to select the detector closes to beam
672 if (beam1.cosAngle(beam) > beam2.cosAngle(beam)) {
673 // det1 is closer, use det1
674 this->setDetectorID(static_cast<int>(det1->getID()));
675 detPos = det1->getPos();
676 } else {
677 // det2 is closer, let's use det2
678 this->setDetectorID(static_cast<int>(det2->getID()));
679 detPos = det2->getPos();
680 }
681 found = true;
682 break;
683 }
684 }
685 }
686 }
687 return found;
688}
689
690//----------------------------------------------------------------------------------------------
692double Peak::getFinalEnergy() const { return m_finalEnergy; }
693
695double Peak::getInitialEnergy() const { return m_initialEnergy; }
696
699
702void Peak::setFinalEnergy(double m_finalEnergy) { this->m_finalEnergy = m_finalEnergy; }
703
706void Peak::setInitialEnergy(double m_initialEnergy) { this->m_initialEnergy = m_initialEnergy; }
707
708// -------------------------------------------------------------------------------------
711
712// -------------------------------------------------------------------------------------
714double Peak::getL1() const { return (m_samplePos - sourcePos).norm(); }
715
716// -------------------------------------------------------------------------------------
718double Peak::getL2() const { return (detPos - m_samplePos).norm(); }
719
725Peak &Peak::operator=(const Peak &other) {
726 if (&other != this) {
727 BasePeak::operator=(other);
728 m_inst = other.m_inst;
729 m_det = other.m_det;
730 m_bankName = other.m_bankName;
731 m_row = other.m_row;
732 m_col = other.m_col;
733 m_detectorID = other.m_detectorID;
734 m_initialEnergy = other.m_initialEnergy;
735 m_finalEnergy = other.m_finalEnergy;
736 sourcePos = other.sourcePos;
737 m_samplePos = other.m_samplePos;
738 detPos = other.detPos;
739 m_detIDs = other.m_detIDs;
740 }
741 return *this;
742}
743
748
754 auto det = getDetector();
755 if (det == nullptr) {
756 throw Mantid::Kernel::Exception::NullPointerException("Peak", "Detector");
757 }
758 return getDetector()->getPos();
759}
760
762
763} // namespace Mantid::DataObjects
double energy
Definition: GetAllEi.cpp:157
Structure describing a single-crystal peak.
Definition: BasePeak.h:33
Mantid::Kernel::Matrix< double > getInverseGoniometerMatrix() const
Get the goniometer rotation matrix at which this peak was measured.
Definition: BasePeak.cpp:214
BasePeak & operator=(BasePeak &&) noexcept=default
Mantid::Kernel::V3D m_samplePos
Cached sample position.
Definition: BasePeak.h:122
void setHKL(double H, double K, double L) override
Set all three H,K,L indices of the peak.
Definition: BasePeak.cpp:132
Mantid::Kernel::Matrix< double > getGoniometerMatrix() const override
Get the goniometer rotation matrix at which this peak was measured.
Definition: BasePeak.cpp:210
virtual double getValueByColName(std::string colName) const
Helper function for displaying/sorting peaks.
Definition: BasePeak.cpp:250
Structure describing a single-crystal peak.
Mantid::Kernel::V3D getQLabFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
Structure describing a single-crystal peak.
Definition: Peak.h:34
int getCol() const override
For RectangularDetectors only, returns the column (x) of the pixel of the detector or -1 if not found...
Definition: Peak.cpp:341
Geometry::Instrument_const_sptr getInstrument() const
Return a shared ptr to the instrument for this peak.
Definition: Peak.cpp:326
Geometry::IDetector_const_sptr m_det
Detector pointed to.
Definition: Peak.h:137
Peak()
Default constructor.
Definition: Peak.cpp:31
double getDSpacing() const override
Calculate the d-spacing of the peak, in 1/Angstroms
Definition: Peak.cpp:416
int m_row
Cached row in the detector.
Definition: Peak.h:143
std::string getBankName() const
Find the name of the bank that is the parent of the detector.
Definition: Peak.cpp:353
const std::set< int > & getContributingDetIDs() const
Return the set of detector IDs that contribute to this peak.
Definition: Peak.cpp:292
void addContributingDetID(const int id)
Add a detector ID that contributed to this peak.
Definition: Peak.cpp:278
static Mantid::Kernel::Logger g_log
Static logger.
Definition: Peak.h:167
Mantid::Kernel::V3D getDetectorPosition() const
Forwarding function.
Definition: Peak.cpp:753
int getRow() const override
For RectangularDetectors only, returns the row (y) of the pixel of the detector or -1 if not found.
Definition: Peak.cpp:332
std::set< int > m_detIDs
List of contributing detectors IDs.
Definition: Peak.h:164
void setWavelength(double wavelength) override
Set the incident wavelength of the neutron.
Definition: Peak.cpp:194
std::string m_bankName
Name of the parent bank.
Definition: Peak.h:140
double getL1() const override
Return the L1 flight path length (source to sample), in meters.
Definition: Peak.cpp:714
void removeContributingDetector(const int id)
Removes an ID from the list of contributing detectors.
Definition: Peak.cpp:285
Mantid::Kernel::V3D detPos
Cached detector position.
Definition: Peak.h:161
Peak & operator=(Peak &&) noexcept=default
double getInitialEnergy() const override
Get the initial (incident) neutron energy in meV.
Definition: Peak.cpp:695
Mantid::Kernel::V3D getQLabFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
Definition: Peak.cpp:441
void setRow(int row)
For RectangularDetectors only, sets the row (y) of the pixel of the detector.
Definition: Peak.cpp:338
void setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame, boost::optional< double > detectorDistance=boost::none) override
Set the peak using the peak's position in reciprocal space, in the sample frame.
Definition: Peak.cpp:492
void setQLabFrame(const Mantid::Kernel::V3D &qLab, boost::optional< double > detectorDistance=boost::none) override
Set the peak using the peak's position in reciprocal space, in the lab frame.
Definition: Peak.cpp:513
void setDetectorID(int id)
Set the detector ID of the pixel at the centre of the peak and look up and cache values related to it...
Definition: Peak.cpp:212
double m_initialEnergy
Initial energy of neutrons at the peak.
Definition: Peak.h:152
void setBankName(std::string bankName)
Set the BankName of this peak.
Definition: Peak.cpp:358
Geometry::Instrument_const_sptr m_inst
Shared pointer to the instrument (for calculating some values )
Definition: Peak.h:134
double getEnergyTransfer() const override
Get the difference between the initial and final neutron energy in meV.
Definition: Peak.cpp:698
Mantid::Kernel::V3D sourcePos
Cached source position.
Definition: Peak.h:158
double getAzimuthal() const override
Calculate the azimuthal angle of the peak
Definition: Peak.cpp:407
int m_col
Cached column in the detector.
Definition: Peak.h:146
bool findDetector()
After creating a peak using the Q in the lab frame, the detPos is set to the direction of the detecto...
Definition: Peak.cpp:613
Geometry::IDetector_const_sptr getDetector() const
Return a shared ptr to the detector at center of peak.
Definition: Peak.cpp:323
void setInitialEnergy(double m_initialEnergy) override
Set the initial energy.
Definition: Peak.cpp:706
double getFinalEnergy() const override
Get the final neutron energy in meV.
Definition: Peak.cpp:692
Kernel::V3D getVirtualDetectorPosition(const Kernel::V3D &detectorDir) const
Get the approximate position of a peak that falls off the detectors.
Definition: Peak.cpp:583
double getWavelength() const override
Calculate the neutron wavelength (in angstroms) at the peak (Note for inelastic scattering - it is th...
Definition: Peak.cpp:364
void setCol(int col)
For RectangularDetectors only, sets the column (x) of the pixel of the detector.
Definition: Peak.cpp:347
double getTOF() const override
Calculate the time of flight (in microseconds) of the neutrons for this peak, using the geometry of t...
Definition: Peak.cpp:379
std::shared_ptr< const Geometry::ReferenceFrame > getReferenceFrame() const override
Return a shared ptr to the reference frame from the instrument for this peak.
Definition: Peak.cpp:329
virtual Mantid::Kernel::V3D getDetPos() const
Return the detector position vector.
Definition: Peak.cpp:710
Mantid::Kernel::V3D getQSampleFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
Definition: Peak.cpp:472
double getL2() const override
Return the L2 flight path length (sample to detector), in meters.
Definition: Peak.cpp:718
int getDetectorID() const
Get the ID of the detector at the center of the peak
Definition: Peak.cpp:271
void setInstrument(const Geometry::Instrument_const_sptr &inst)
Set the instrument (and save the source/sample pos).
Definition: Peak.cpp:300
void setFinalEnergy(double m_finalEnergy) override
Set the final energy.
Definition: Peak.cpp:702
double getScattering() const override
Calculate the scattering angle of the peak
Definition: Peak.cpp:397
double getValueByColName(std::string colName) const override
Helper function for displaying/sorting peaks.
Definition: Peak.cpp:593
Mantid::Kernel::V3D getDetectorPositionNoCheck() const
Forwarding function.
Definition: Peak.cpp:747
double m_finalEnergy
Final energy of the neutrons at peak (normally same as m_InitialEnergy)
Definition: Peak.h:155
int m_detectorID
ID of the detector.
Definition: Peak.h:149
HKL : HKL MDFrame.
Definition: HKL.h:21
Structure describing a single-crystal peak.
Definition: IPeak.h:26
This class is responsible for tracking rays and accumulating a list of objects that are intersected a...
IDetector_const_sptr getDetectorResult() const
Gets the results of the trace, then returns the first detector (that is NOT a monitor) found in the r...
void traceFromSample(const Kernel::V3D &dir) const
Trace a given track from the sample position in the given direction.
Defines a track as a start point and a direction.
Definition: Track.h:165
Exception for errors associated with the instrument definition.
Definition: Exception.h:220
Exception thrown when an attempt is made to dereference a null pointer.
Definition: Exception.h:305
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
void debug(const std::string &msg)
Logs at debug level.
Definition: Logger.cpp:114
Numerical Matrix class.
Definition: Matrix.h:42
Class for 3D vectors.
Definition: V3D.h:34
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
Definition: V3D.h:274
constexpr double X() const noexcept
Get x.
Definition: V3D.h:232
double normalize()
Make a normalized vector (return norm value)
Definition: V3D.cpp:130
constexpr double Y() const noexcept
Get y.
Definition: V3D.h:233
std::string toString() const
Definition: V3D.cpp:340
double angle(const V3D &) const
Angle between this and another vector.
Definition: V3D.cpp:165
double norm() const noexcept
Definition: V3D.h:263
double cosAngle(const V3D &) const
cos(Angle) between this and another vector
Definition: V3D.cpp:180
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
Definition: IComponent.h:161
std::shared_ptr< const RectangularDetector > RectangularDetector_const_sptr
std::shared_ptr< const Mantid::Geometry::IDetector > IDetector_const_sptr
Shared pointer to IDetector (const version)
Definition: IDetector.h:102
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
std::shared_ptr< Mantid::Geometry::IDetector > IDetector_sptr
Shared pointer to IDetector.
Definition: IDetector.h:100
MANTID_KERNEL_DLL int endsWithInt(const std::string &word)
Get an int from the end of a word.
Definition: Strings.cpp:210
MANTID_KERNEL_DLL V3D normalize(V3D v)
Normalizes a V3D.
Definition: V3D.h:341
static constexpr double NeutronMass
Mass of the neutron in kg.
static constexpr double h
Planck constant in J*s.
static constexpr double meV
1 meV in Joules.
static constexpr double h_bar
Planck constant in J*s, divided by 2 PI.
Helper class which provides the Collimation Length for SANS instruments.
int32_t detid_t
Typedef for a detector ID.
Definition: SpectrumInfo.h:21