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 +
18#include "MantidKernel/Logger.h"
20
21#include "boost/make_shared.hpp"
22
23#include <algorithm>
24#include <cctype>
25#include <string>
26#include <utility>
27
28using namespace Mantid;
29using namespace Mantid::Kernel;
30using namespace Mantid::Geometry;
31
32namespace Mantid::DataObjects {
33
34namespace {
43template <typename Func> bool withRayTracer(Instrument const &inst, Func const &func) {
44 if (inst.isParametrized()) {
45 auto const &pmap = *inst.getParameterMap();
46 return func(InstrumentRayTracer(pmap.componentInfo(), pmap.detectorInfo()));
47 }
48 auto const [compInfo, detInfo] = InstrumentVisitor::makeWrappers(inst);
49 return func(InstrumentRayTracer(*compInfo, *detInfo));
50}
51} // namespace
52
53//----------------------------------------------------------------------------------------------
55Peak::Peak() : BasePeak(), m_row(-1), m_col(-1), m_detectorID(-1), m_initialEnergy(0.), m_finalEnergy(0.) {}
56
57//----------------------------------------------------------------------------------------------
68 std::optional<double> detectorDistance)
69 : BasePeak() {
70 // Initialization of m_inst, sourcePos, m_samplePos
72 // Initialization of m_detectorID, detPos, m_det, m_row, m_col, m_bankName, m_initialEnergy, m_finalEnergy
73 setQLabFrame(QLabFrame, std::move(detectorDistance));
74}
75
76//----------------------------------------------------------------------------------------------
90 const Mantid::Kernel::Matrix<double> &goniometer, std::optional<double> detectorDistance)
91 : BasePeak(goniometer) {
92 // Initialization of m_inst, sourcePos, m_samplePos
93 this->setInstrument(m_inst);
94 // Initialization of m_detectorID, detPos, m_det, m_row, m_col, m_bankName, m_initialEnergy, m_finalEnergy
95 this->setQSampleFrame(QSampleFrame, std::move(detectorDistance));
96}
97
98//----------------------------------------------------------------------------------------------
105Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID, double m_Wavelength) : BasePeak() {
106 // Initialization of m_inst, sourcePos, m_samplePos
107 this->setInstrument(m_inst);
108 // Initialization of m_detectorID, detPos, m_det, m_row, m_col, m_bankName
109 this->setDetectorID(m_detectorID);
110 // Initialization of m_initialEnergy, m_finalEnergy
111 this->setWavelength(m_Wavelength);
112}
113
114//----------------------------------------------------------------------------------------------
122Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID, double m_Wavelength,
124 : BasePeak() {
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//----------------------------------------------------------------------------------------------
143Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID, double m_Wavelength,
145 : BasePeak(goniometer) {
146 // Initialization of m_inst, sourcePos, m_samplePos
147 this->setInstrument(m_inst);
148 // Initialization of m_detectorID, detPos, m_det, m_row, m_col, m_bankName
149 this->setDetectorID(m_detectorID);
150 // Initialization of m_initialEnergy, m_finalEnergy
151 this->setWavelength(m_Wavelength);
152 this->setHKL(HKL);
153}
154
155//----------------------------------------------------------------------------------------------
162Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, double scattering, double m_Wavelength)
163 : BasePeak(), m_row(-1), m_col(-1) {
164 // Initialization of m_inst, sourcePos, m_samplePos
165 this->setInstrument(m_inst);
166 // Initialization of m_initialEnergy, m_finalEnergy
167 this->setWavelength(m_Wavelength);
168 m_detectorID = -1;
169 // get the approximate location of the detector
170 const auto detectorDir = V3D(sin(scattering), 0.0, cos(scattering));
171 detPos = getVirtualDetectorPosition(detectorDir);
172}
173
178Peak::Peak(const Peak &other) = default;
179
180//----------------------------------------------------------------------------------------------
187 : BasePeak(ipeak), m_initialEnergy(ipeak.getInitialEnergy()), m_finalEnergy(ipeak.getFinalEnergy()) {
188 const auto *peak = dynamic_cast<const Peak *>(&ipeak);
189 if (!peak)
190 throw std::invalid_argument("Cannot construct a Peak from this non-Peak object");
191 setInstrument(peak->getInstrument());
192 detid_t id = peak->getDetectorID();
193 if (id >= 0)
194 setDetectorID(id);
195 this->m_detIDs = peak->m_detIDs;
196}
197
198//----------------------------------------------------------------------------------------------
200 std::optional<double> detectorDistance)
201 : BasePeak(lpeak) {
202 this->setInstrument(inst);
203 this->setQLabFrame(lpeak.getQLabFrame(), std::move(detectorDistance));
204}
205
206//----------------------------------------------------------------------------------------------
212void Peak::setWavelength(double wavelength) {
213 // Velocity of the neutron (non-relativistic)
214 double velocity = PhysicalConstants::h / (wavelength * 1e-10 * PhysicalConstants::NeutronMass);
215 // Energy in J of the neutron
216 double energy = PhysicalConstants::NeutronMass * velocity * velocity / 2.0;
217 // Convert to meV
220}
221
222//----------------------------------------------------------------------------------------------
231 if (!m_inst)
232 throw std::runtime_error("Peak::setInstrument(): No instrument is set!");
233 this->m_det = m_inst->getDetector(id);
234 if (!m_det)
235 throw std::runtime_error("Peak::setInstrument(): No detector was found!");
236
237 this->m_detectorID = id;
239
240 detPos = m_det->getPos();
241
242 // We now look for the row/column. -1 if not found.
243 setRow(-1);
244 setCol(-1);
245
246 // Go up 2 parents to find the bank/rectangular detector
247 IComponent_const_sptr parent = m_det->getParent();
248
249 // Find the ROW by looking at the string name of the pixel. E.g. "pixel12"
250 // gives row 12.
251 setRow(Strings::endsWithInt(m_det->getName()));
252
253 if (!parent)
254 return;
255 setBankName(parent->getName());
256
257 // Find the COLUMN by looking at the string name of the parent. E.g. "tube003"
258 // gives column 3.
259 setCol(Strings::endsWithInt(parent->getName()));
260
261 parent = parent->getParent();
262 // Use the parent if there is no grandparent.
263 if (!parent)
264 return;
265
266 // Use the parent if the grandparent is the instrument
267 Instrument_const_sptr instrument = std::dynamic_pointer_cast<const Instrument>(parent);
268 if (instrument)
269 return;
270 // Use the grand-parent whenever possible
271 setBankName(parent->getName());
272 // For CORELLI, one level above sixteenpack
273 if (getBankName() == "sixteenpack") {
274 parent = parent->getParent();
275 setBankName(parent->getName());
276 }
277
278 // Special for rectangular detectors: find the row and column.
279 RectangularDetector_const_sptr retDet = std::dynamic_pointer_cast<const RectangularDetector>(parent);
280 if (!retDet)
281 return;
282 std::pair<int, int> xy = retDet->getXYForDetectorID(m_detectorID);
283 setRow(xy.second);
284 setCol(xy.first);
285}
286
287//----------------------------------------------------------------------------------------------
289int Peak::getDetectorID() const { return m_detectorID; }
290
291//----------------------------------------------------------------------------------------------
296void Peak::addContributingDetID(const int id) { m_detIDs.insert(id); }
297
298//-------------------------------------------------------------------------------------
303void Peak::removeContributingDetector(const int id) { m_detIDs.erase(id); }
304
305//----------------------------------------------------------------------------------------------
310const std::set<int> &Peak::getContributingDetIDs() const { return m_detIDs; }
311
312//----------------------------------------------------------------------------------------------
319 m_inst = inst;
320 if (!inst)
321 throw std::runtime_error("Peak::setInstrument(): No instrument is set!");
322
323 // Cache some positions
324 const Geometry::IComponent_const_sptr sourceObj = m_inst->getSource();
325 if (sourceObj == nullptr)
326 throw Exception::InstrumentDefinitionError("Peak::setInstrument(): Failed "
327 "to get source component from "
328 "instrument");
329 const Geometry::IComponent_const_sptr sampleObj = m_inst->getSample();
330 if (sampleObj == nullptr)
331 throw Exception::InstrumentDefinitionError("Peak::setInstrument(): Failed "
332 "to get sample component from "
333 "instrument");
334
335 sourcePos = sourceObj->getPos();
336 m_samplePos = sampleObj->getPos();
337}
338
339//----------------------------------------------------------------------------------------------
342
345
347std::shared_ptr<const Geometry::ReferenceFrame> Peak::getReferenceFrame() const { return m_inst->getReferenceFrame(); }
348
350int Peak::getRow() const { return m_row; }
351
356void Peak::setRow(int row) { m_row = row; }
357
359int Peak::getCol() const { return m_col; }
360
365void Peak::setCol(int col) { m_col = col; }
366
371const std::string &Peak::getBankName() const { return m_bankName; }
372
376void Peak::setBankName(std::string bankName) { this->m_bankName = std::move(bankName); }
377
378// -------------------------------------------------------------------------------------
382double Peak::getWavelength() const {
383 // Energy in J of the neutron
385 // v = sqrt(2.0 * E / m)
386 double velocity = sqrt(2.0 * energy / PhysicalConstants::NeutronMass);
387 // wavelength = h / mv
388 double wavelength = PhysicalConstants::h / (PhysicalConstants::NeutronMass * velocity);
389 // Return it in angstroms
390 return wavelength * 1e10;
391}
392
393// -------------------------------------------------------------------------------------
397double Peak::getTOF() const {
398 // First, get the neutron traveling distances
399 double L1 = this->getL1();
400 double L2 = this->getL2();
401 // Energy in J of the neutron
404 // v = sqrt(2 * E / m)
405 double vi = sqrt(2.0 * Ei / PhysicalConstants::NeutronMass);
406 double vf = sqrt(2.0 * Ef / PhysicalConstants::NeutronMass);
407 // Time of flight in seconds = distance / speed
408 double tof = L1 / vi + L2 / vf;
409 // Return in microsecond units
410 return tof * 1e6;
411}
412
413// -------------------------------------------------------------------------------------
415double Peak::getScattering() const {
416 // The detector is at 2 theta scattering angle
417 V3D beamDir = m_samplePos - sourcePos;
418 V3D detDir = detPos - m_samplePos;
419
420 return detDir.angle(beamDir);
421}
422
423// -------------------------------------------------------------------------------------
425double Peak::getAzimuthal() const {
426 // The detector is at 2 theta scattering angle
427 V3D detDir = detPos - m_samplePos;
428
429 return atan2(detDir.Y(), detDir.X());
430}
431
432// -------------------------------------------------------------------------------------
435 V3D detDir = detPos - m_samplePos;
436 detDir /= detDir.norm();
437 return getInverseGoniometerMatrix() * detDir;
438}
439
440// -------------------------------------------------------------------------------------
443 V3D beamDir = m_samplePos - sourcePos;
444 beamDir /= beamDir.norm();
445 return getInverseGoniometerMatrix() * beamDir * -1.0;
446}
447
448// -------------------------------------------------------------------------------------
450double Peak::getDSpacing() const {
451 // The detector is at 2 theta scattering angle
452 V3D beamDir = m_samplePos - sourcePos;
453 V3D detDir = detPos - m_samplePos;
454
455 double two_theta;
456 try {
457 two_theta = detDir.angle(beamDir);
458 } catch (std::runtime_error &) {
459 two_theta = 0.;
460 }
461
462 // In general case (2*pi/d)^2=k_i^2+k_f^2-2*k_i*k_f*cos(two_theta)
463 // E_i,f=k_i,f^2*hbar^2/(2 m)
466 2.0 * sqrt(getInitialEnergy() * getFinalEnergy()) * cos(two_theta));
467}
468
469//----------------------------------------------------------------------------------------------
476 // Normalized beam direction
477 V3D beamDir = m_samplePos - sourcePos;
478 beamDir /= beamDir.norm();
479 // Normalized detector direction
480 V3D detDir = (detPos - m_samplePos);
481 detDir /= detDir.norm();
482
483 // Energy in J of the neutron
485 // v = sqrt(2.0 * E / m)
486 double vi = sqrt(2.0 * ei / PhysicalConstants::NeutronMass);
487 // wavenumber = h_bar / mv
489 // in angstroms
490 wi *= 1e10;
491 // wavevector=1/wavenumber = 2pi/wavelength
492 double wvi = 1.0 / wi;
493 // Now calculate the wavevector of the scattered neutron
494 double wvf = (2.0 * M_PI) / this->getWavelength();
495 // And Q in the lab frame
496 // Default for ki-kf is positive
497 double qSign = 1.0;
498 if (m_convention == "Crystallography")
499 qSign = -1.0;
500 return (beamDir * wvi - detDir * wvf) * qSign;
501}
502
503//----------------------------------------------------------------------------------------------
507 V3D Qlab = this->getQLabFrame();
508 // Multiply by the inverse of the goniometer matrix to get the sample frame
509 V3D Qsample = getInverseGoniometerMatrix() * Qlab;
510 return Qsample;
511}
512
513//----------------------------------------------------------------------------------------------
526void Peak::setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame, std::optional<double> detectorDistance) {
527 V3D Qlab = getGoniometerMatrix() * QSampleFrame;
528 this->setQLabFrame(Qlab, detectorDistance);
529}
530
531//----------------------------------------------------------------------------------------------
547void Peak::setQLabFrame(const Mantid::Kernel::V3D &qLab, std::optional<double> detectorDistance) {
548 if (!this->m_inst) {
549 throw std::invalid_argument("Setting QLab without an instrument would lead "
550 "to an inconsistent state for the Peak");
551 }
552 // Clear out the detector = we can't know them
553 m_detectorID = -1;
554 detPos = V3D();
556 m_row = -1;
557 m_col = -1;
558 setBankName("None");
559
560 /* The q-vector direction of the peak is = goniometer * ub * hkl_vector
561 * The incident neutron wavevector is along the beam direction, ki = 1/wl
562 * (usually z, but referenceframe is definitive).
563 * In the inelastic convention, q = ki - kf.
564 * The final neutron wavector kf = -qx in x; -qy in y; and (-q.beam_dir+1/wl)
565 * in beam direction.
566 * AND: norm(kf) = norm(ki) = 2*pi/wavelength
567 * THEREFORE: 1/wl = norm(q)^2 / (2*q.beam_dir)
568 */
569 const double norm_q = qLab.norm();
570 if (norm_q == 0.0)
571 throw std::invalid_argument("Peak::setQLabFrame(): Q cannot be 0,0,0.");
572
573 std::shared_ptr<const ReferenceFrame> refFrame = this->m_inst->getReferenceFrame();
574 const V3D refBeamDir = refFrame->vecPointingAlongBeam();
575 // Default for ki-kf has -q
576 const double qSign = (m_convention != "Crystallography") ? 1.0 : -1.0;
577 const double qBeam = qLab.scalar_prod(refBeamDir) * qSign;
578
579 if (qBeam == 0.0)
580 throw std::invalid_argument("Peak::setQLabFrame(): Q cannot be 0 in the beam direction.");
581
582 const double one_over_wl = (norm_q * norm_q) / (2.0 * qBeam);
583 const double wl = (2.0 * M_PI) / one_over_wl;
584 if (wl < 0.0) {
585 std::ostringstream mess;
586 mess << "Peak::setQLabFrame(): Wavelength found was negative (" << wl << " Ang)! This Q is not physical.";
587 throw std::invalid_argument(mess.str());
588 }
589
590 // Save the wavelength
591 this->setWavelength(wl);
592
593 V3D detectorDir = -qLab * qSign;
594 detectorDir[refFrame->pointingAlongBeam()] = one_over_wl - qBeam;
595 detectorDir.normalize();
596
597 // Use the given detector distance to find the detector position.
598 if (detectorDistance.has_value()) {
599 detPos = m_samplePos + detectorDir * detectorDistance.value();
600 // We do not-update the detector as by manually setting the distance the
601 // client seems to know better.
602 } else {
603 // Find the detector
604 const bool found = withRayTracer(
605 *m_inst, [this, &detectorDir](InstrumentRayTracer const &tracer) { return findDetector(detectorDir, tracer); });
606 if (!found) {
607 // This is important, so we ought to log when this fails to happen.
608 g_log.debug("Could not find detector after setting qLab via setQLab with "
609 "QLab : " +
610 qLab.toString());
611
612 detPos = getVirtualDetectorPosition(detectorDir);
613 }
614 }
615}
616
617V3D Peak::getVirtualDetectorPosition(const V3D &detectorDir) const {
618 const auto component = getInstrument()->getComponentByName("extended-detector-space");
619 if (!component) {
620 return detectorDir; // the best idea we have is just the direction
621 }
622 const auto object = std::dynamic_pointer_cast<const ObjComponent>(component);
623 const auto distance = object->shape()->distance(Geometry::Track(m_samplePos, detectorDir));
624 return detectorDir * distance;
625}
626
627double Peak::getValueByColName(std::string name) const {
628 std::transform(name.begin(), name.end(), name.begin(), ::tolower);
629 std::map<std::string, double> colVals = {
630 {"detid", double(m_detectorID)}, {"row", double(m_row)}, {"col", double(m_col)}};
631 auto it = colVals.find(name);
632 if (it != colVals.end())
633 return it->second;
634 else
636}
637
648 return withRayTracer(*m_inst, [this](InstrumentRayTracer const &tracer) { return findDetector(tracer); });
649}
650
660 // Scattered beam direction
661 const V3D beam = normalize(detPos - m_samplePos);
662
663 return findDetector(beam, tracer);
664}
665
674 bool found = false;
675 // Create a ray tracer
676 auto const &detInfo = tracer.detectorInfo();
677 tracer.traceFromSample(beam);
678 auto const detIndex = tracer.getDetectorResult();
679 if (detIndex != ComponentInfo::invalidIndex) {
680 // Set the detector ID, the row, col, etc.
681 this->setDetectorID(detInfo.detid(detIndex));
682 // The old detector position is not more precise if it comes from
683 // FindPeaksMD
684 detPos = detInfo.position(detIndex);
685 found = true;
686 }
687 // Use tube-gap parameter in instrument parameter file to find peaks with
688 // center in gaps between tubes
689 else if (m_inst->hasParameter("tube-gap")) {
690 std::vector<double> gaps = m_inst->getNumberParameter("tube-gap", true);
691 if (!gaps.empty()) {
692 const auto gap = static_cast<double>(gaps.front());
693 // try adding and subtracting tube-gap in 3 q dimensions to see if you can
694 // find detectors on each side of tube gap
695 for (int i = 0; i < 3; i++) {
696 V3D gapDir;
697 gapDir[i] = gap;
698 V3D beam1 = beam + gapDir;
699 tracer.traceFromSample(normalize(beam1));
700 auto const detIndex1 = tracer.getDetectorResult();
701 V3D beam2 = beam - gapDir;
702 tracer.traceFromSample(normalize(beam2));
703 auto const detIndex2 = tracer.getDetectorResult();
704 if (detIndex1 != ComponentInfo::invalidIndex && detIndex2 != ComponentInfo::invalidIndex) {
705 // compute the cosAngle to select the detector closes to beam
706 if (beam1.cosAngle(beam) > beam2.cosAngle(beam)) {
707 // det1 is closer, use det1
708 this->setDetectorID(detInfo.detid(detIndex1));
709 detPos = detInfo.position(detIndex1);
710 } else {
711 // det2 is closer, let's use det2
712 this->setDetectorID(detInfo.detid(detIndex2));
713 detPos = detInfo.position(detIndex2);
714 }
715 found = true;
716 break;
717 }
718 }
719 }
720 }
721 return found;
722}
723
724//----------------------------------------------------------------------------------------------
726double Peak::getFinalEnergy() const { return m_finalEnergy; }
727
729double Peak::getInitialEnergy() const { return m_initialEnergy; }
730
733
736void Peak::setFinalEnergy(double m_finalEnergy) { this->m_finalEnergy = m_finalEnergy; }
737
740void Peak::setInitialEnergy(double m_initialEnergy) { this->m_initialEnergy = m_initialEnergy; }
741
742// -------------------------------------------------------------------------------------
745
746// -------------------------------------------------------------------------------------
748double Peak::getL1() const { return (m_samplePos - sourcePos).norm(); }
749
750// -------------------------------------------------------------------------------------
752double Peak::getL2() const { return (detPos - m_samplePos).norm(); }
753
759Peak &Peak::operator=(const Peak &other) {
760 if (&other != this) {
761 BasePeak::operator=(other);
762 m_inst = other.m_inst;
763 m_det = other.m_det;
764 m_bankName = other.m_bankName;
765 m_row = other.m_row;
766 m_col = other.m_col;
767 m_detectorID = other.m_detectorID;
768 m_initialEnergy = other.m_initialEnergy;
769 m_finalEnergy = other.m_finalEnergy;
770 sourcePos = other.sourcePos;
771 m_samplePos = other.m_samplePos;
772 detPos = other.detPos;
773 m_detIDs = other.m_detIDs;
774 }
775 return *this;
776}
777
782
788 auto det = getDetector();
789 if (det == nullptr) {
790 throw Mantid::Kernel::Exception::NullPointerException("Peak", "Detector");
791 }
792 return getDetector()->getPos();
793}
794
796
797} // namespace Mantid::DataObjects
std::string name
Definition Run.cpp:60
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 final
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:359
void setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame, std::optional< double > detectorDistance=std::nullopt) override
Set the peak using the peak's position in reciprocal space, in the sample frame.
Definition Peak.cpp:526
Mantid::Kernel::V3D getSourceDirectionSampleFrame() const override
Calculate the reverse incident beam direction in the sample frame
Definition Peak.cpp:442
Geometry::Instrument_const_sptr getInstrument() const
Return a shared ptr to the instrument for this peak.
Definition Peak.cpp:344
Geometry::IDetector_const_sptr m_det
Detector pointed to.
Definition Peak.h:143
Peak()
Default constructor.
Definition Peak.cpp:55
double getDSpacing() const override
Calculate the d-spacing of the peak, in 1/Angstroms
Definition Peak.cpp:450
int m_row
Cached row in the detector.
Definition Peak.h:149
const std::set< int > & getContributingDetIDs() const
Return the set of detector IDs that contribute to this peak.
Definition Peak.cpp:310
void addContributingDetID(const int id)
Add a detector ID that contributed to this peak.
Definition Peak.cpp:296
static Mantid::Kernel::Logger g_log
Static logger.
Definition Peak.h:173
Mantid::Kernel::V3D getDetectorPosition() const
Forwarding function.
Definition Peak.cpp:787
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:350
std::set< int > m_detIDs
List of contributing detectors IDs.
Definition Peak.h:170
void setWavelength(double wavelength) override
Set the incident wavelength of the neutron.
Definition Peak.cpp:212
std::string m_bankName
Name of the parent bank.
Definition Peak.h:146
double getL1() const override
Return the L1 flight path length (source to sample), in meters.
Definition Peak.cpp:748
void removeContributingDetector(const int id)
Removes an ID from the list of contributing detectors.
Definition Peak.cpp:303
Mantid::Kernel::V3D detPos
Cached detector position.
Definition Peak.h:167
Peak & operator=(Peak &&) noexcept=default
double getInitialEnergy() const override
Get the initial (incident) neutron energy in meV.
Definition Peak.cpp:729
Mantid::Kernel::V3D getQLabFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
Definition Peak.cpp:475
void setRow(int row)
For RectangularDetectors only, sets the row (y) of the pixel of the detector.
Definition Peak.cpp:356
void setQLabFrame(const Mantid::Kernel::V3D &qLab, std::optional< double > detectorDistance=std::nullopt) final
Set the peak using the peak's position in reciprocal space, in the lab frame.
Definition Peak.cpp:547
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:230
double m_initialEnergy
Initial energy of neutrons at the peak.
Definition Peak.h:158
void setBankName(std::string bankName)
Set the BankName of this peak.
Definition Peak.cpp:376
Geometry::Instrument_const_sptr m_inst
Shared pointer to the instrument (for calculating some values )
Definition Peak.h:140
double getEnergyTransfer() const override
Get the difference between the initial and final neutron energy in meV.
Definition Peak.cpp:732
int getDetectorID() const override
Get the ID of the detector at the center of the peak
Definition Peak.cpp:289
Mantid::Kernel::V3D sourcePos
Cached source position.
Definition Peak.h:164
double getAzimuthal() const override
Calculate the azimuthal angle of the peak
Definition Peak.cpp:425
int m_col
Cached column in the detector.
Definition Peak.h:152
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:647
Geometry::IDetector_const_sptr getDetector() const
Return a shared ptr to the detector at center of peak.
Definition Peak.cpp:341
Mantid::Kernel::V3D getDetectorDirectionSampleFrame() const override
Calculate the scattered beam direction in the sample frame
Definition Peak.cpp:434
void setInitialEnergy(double m_initialEnergy) override
Set the initial energy.
Definition Peak.cpp:740
double getFinalEnergy() const override
Get the final neutron energy in meV.
Definition Peak.cpp:726
Kernel::V3D getVirtualDetectorPosition(const Kernel::V3D &detectorDir) const
Get the approximate position of a peak that falls off the detectors.
Definition Peak.cpp:617
double getWavelength() const override
Calculate the neutron wavelength (in angstroms) at the peak (Note for inelastic scattering - it is th...
Definition Peak.cpp:382
void setCol(int col)
For RectangularDetectors only, sets the column (x) of the pixel of the detector.
Definition Peak.cpp:365
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:397
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:347
virtual Mantid::Kernel::V3D getDetPos() const
Return the detector position vector.
Definition Peak.cpp:744
Mantid::Kernel::V3D getQSampleFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
Definition Peak.cpp:506
double getL2() const override
Return the L2 flight path length (sample to detector), in meters.
Definition Peak.cpp:752
const std::string & getBankName() const
Find the name of the bank that is the parent of the detector.
Definition Peak.cpp:371
void setInstrument(const Geometry::Instrument_const_sptr &inst)
Set the instrument (and save the source/sample pos).
Definition Peak.cpp:318
void setFinalEnergy(double m_finalEnergy) override
Set the final energy.
Definition Peak.cpp:736
double getScattering() const override
Calculate the scattering angle of the peak
Definition Peak.cpp:415
double getValueByColName(std::string colName) const override
Helper function for displaying/sorting peaks.
Definition Peak.cpp:627
Mantid::Kernel::V3D getDetectorPositionNoCheck() const
Forwarding function.
Definition Peak.cpp:781
double m_finalEnergy
Final energy of the neutrons at peak (normally same as m_InitialEnergy)
Definition Peak.h:161
int m_detectorID
ID of the detector.
Definition Peak.h:155
static constexpr size_t invalidIndex
Returned by indexOfOrInvalid() for a component ID that is not part of this instrument.
bool isParametrized() const override
Return true if the Component is, in fact, parametrized (that is - it has a valid parameter map)
Definition Component.cpp:75
HKL : HKL MDFrame.
Definition HKL.h:20
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...
const DetectorInfo & detectorInfo() const
void traceFromSample(const Kernel::V3D &dir) const
Trace a given track from the sample position in the given direction.
size_t getDetectorResult() const
Get the index of the first non-monitor detector intersected since the previous call to trace,...
std::pair< std::unique_ptr< ComponentInfo >, std::unique_ptr< DetectorInfo > > makeWrappers() const
Make the wrappers from the data collected by walkInstrument(), which must be called first.
Base Instrument Class.
Definition Instrument.h:50
std::shared_ptr< ParameterMap > getParameterMap() const
Pointer to the NOT const ParameterMap holding the parameters of the modified instrument components.
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:51
void debug(const std::string &msg)
Logs at debug level.
Definition Logger.cpp:145
Numerical Matrix class.
Definition Matrix.h:41
Class for 3D vectors.
Definition V3D.h:35
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
Definition V3D.h:281
constexpr double X() const noexcept
Get x.
Definition V3D.h:239
double normalize()
Make a normalized vector (return norm value)
Definition V3D.cpp:129
constexpr double Y() const noexcept
Get y.
Definition V3D.h:240
std::string toString() const
Definition V3D.cpp:332
double angle(const V3D &) const
Angle between this and another vector.
Definition V3D.cpp:162
double norm() const noexcept
Definition V3D.h:270
double cosAngle(const V3D &) const
cos(Angle) between this and another vector
Definition V3D.cpp:177
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
Definition IComponent.h:165
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:96
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:94
MANTID_KERNEL_DLL int endsWithInt(const std::string &word)
Get an int from the end of a word.
Definition Strings.cpp:233
MANTID_KERNEL_DLL V3D normalize(V3D v)
Normalizes a V3D.
Definition V3D.h:353
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.
Generate a tableworkspace to store the calibration results.