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 std::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, std::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//----------------------------------------------------------------------------------------------
81Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID, double m_Wavelength) : BasePeak() {
82 // Initialization of m_inst, sourcePos, m_samplePos
83 this->setInstrument(m_inst);
84 // Initialization of m_detectorID, detPos, m_det, m_row, m_col, m_bankName
85 this->setDetectorID(m_detectorID);
86 // Initialization of m_initialEnergy, m_finalEnergy
87 this->setWavelength(m_Wavelength);
88}
89
90//----------------------------------------------------------------------------------------------
98Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID, double m_Wavelength,
100 : BasePeak() {
101 // Initialization of m_inst, sourcePos, m_samplePos
102 this->setInstrument(m_inst);
103 // Initialization of m_detectorID, detPos, m_det, m_row, m_col, m_bankName
104 this->setDetectorID(m_detectorID);
105 // Initialization of m_initialEnergy, m_finalEnergy
106 this->setWavelength(m_Wavelength);
107 this->setHKL(HKL);
108}
109
110//----------------------------------------------------------------------------------------------
119Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID, double m_Wavelength,
121 : BasePeak(goniometer) {
122 // Initialization of m_inst, sourcePos, m_samplePos
123 this->setInstrument(m_inst);
124 // Initialization of m_detectorID, detPos, m_det, m_row, m_col, m_bankName
125 this->setDetectorID(m_detectorID);
126 // Initialization of m_initialEnergy, m_finalEnergy
127 this->setWavelength(m_Wavelength);
128 this->setHKL(HKL);
129}
130
131//----------------------------------------------------------------------------------------------
138Peak::Peak(const Geometry::Instrument_const_sptr &m_inst, double scattering, double m_Wavelength)
139 : BasePeak(), m_row(-1), m_col(-1) {
140 // Initialization of m_inst, sourcePos, m_samplePos
141 this->setInstrument(m_inst);
142 // Initialization of m_initialEnergy, m_finalEnergy
143 this->setWavelength(m_Wavelength);
144 m_detectorID = -1;
145 // get the approximate location of the detector
146 const auto detectorDir = V3D(sin(scattering), 0.0, cos(scattering));
147 detPos = getVirtualDetectorPosition(detectorDir);
148}
149
154Peak::Peak(const Peak &other) = default;
155
156//----------------------------------------------------------------------------------------------
163 : BasePeak(ipeak), m_initialEnergy(ipeak.getInitialEnergy()), m_finalEnergy(ipeak.getFinalEnergy()) {
164 const auto *peak = dynamic_cast<const Peak *>(&ipeak);
165 if (!peak)
166 throw std::invalid_argument("Cannot construct a Peak from this non-Peak object");
167 setInstrument(peak->getInstrument());
168 detid_t id = peak->getDetectorID();
169 if (id >= 0)
170 setDetectorID(id);
171 this->m_detIDs = peak->m_detIDs;
172}
173
174//----------------------------------------------------------------------------------------------
176 std::optional<double> detectorDistance)
177 : BasePeak(lpeak) {
178 this->setInstrument(inst);
179 this->setQLabFrame(lpeak.getQLabFrame(), std::move(detectorDistance));
180}
181
182//----------------------------------------------------------------------------------------------
188void Peak::setWavelength(double wavelength) {
189 // Velocity of the neutron (non-relativistic)
190 double velocity = PhysicalConstants::h / (wavelength * 1e-10 * PhysicalConstants::NeutronMass);
191 // Energy in J of the neutron
192 double energy = PhysicalConstants::NeutronMass * velocity * velocity / 2.0;
193 // Convert to meV
196}
197
198//----------------------------------------------------------------------------------------------
207 if (!m_inst)
208 throw std::runtime_error("Peak::setInstrument(): No instrument is set!");
209 this->m_det = m_inst->getDetector(id);
210 if (!m_det)
211 throw std::runtime_error("Peak::setInstrument(): No detector was found!");
212
213 this->m_detectorID = id;
215
216 detPos = m_det->getPos();
217
218 // We now look for the row/column. -1 if not found.
219 setRow(-1);
220 setCol(-1);
221
222 // Go up 2 parents to find the bank/rectangular detector
223 IComponent_const_sptr parent = m_det->getParent();
224
225 // Find the ROW by looking at the string name of the pixel. E.g. "pixel12"
226 // gives row 12.
227 setRow(Strings::endsWithInt(m_det->getName()));
228
229 if (!parent)
230 return;
231 setBankName(parent->getName());
232
233 // Find the COLUMN by looking at the string name of the parent. E.g. "tube003"
234 // gives column 3.
235 setCol(Strings::endsWithInt(parent->getName()));
236
237 parent = parent->getParent();
238 // Use the parent if there is no grandparent.
239 if (!parent)
240 return;
241
242 // Use the parent if the grandparent is the instrument
243 Instrument_const_sptr instrument = std::dynamic_pointer_cast<const Instrument>(parent);
244 if (instrument)
245 return;
246 // Use the grand-parent whenever possible
247 setBankName(parent->getName());
248 // For CORELLI, one level above sixteenpack
249 if (getBankName() == "sixteenpack") {
250 parent = parent->getParent();
251 setBankName(parent->getName());
252 }
253
254 // Special for rectangular detectors: find the row and column.
255 RectangularDetector_const_sptr retDet = std::dynamic_pointer_cast<const RectangularDetector>(parent);
256 if (!retDet)
257 return;
258 std::pair<int, int> xy = retDet->getXYForDetectorID(m_detectorID);
259 setRow(xy.second);
260 setCol(xy.first);
261}
262
263//----------------------------------------------------------------------------------------------
265int Peak::getDetectorID() const { return m_detectorID; }
266
267//----------------------------------------------------------------------------------------------
272void Peak::addContributingDetID(const int id) { m_detIDs.insert(id); }
273
274//-------------------------------------------------------------------------------------
279void Peak::removeContributingDetector(const int id) { m_detIDs.erase(id); }
280
281//----------------------------------------------------------------------------------------------
286const std::set<int> &Peak::getContributingDetIDs() const { return m_detIDs; }
287
288//----------------------------------------------------------------------------------------------
295 m_inst = inst;
296 if (!inst)
297 throw std::runtime_error("Peak::setInstrument(): No instrument is set!");
298
299 // Cache some positions
300 const Geometry::IComponent_const_sptr sourceObj = m_inst->getSource();
301 if (sourceObj == nullptr)
302 throw Exception::InstrumentDefinitionError("Peak::setInstrument(): Failed "
303 "to get source component from "
304 "instrument");
305 const Geometry::IComponent_const_sptr sampleObj = m_inst->getSample();
306 if (sampleObj == nullptr)
307 throw Exception::InstrumentDefinitionError("Peak::setInstrument(): Failed "
308 "to get sample component from "
309 "instrument");
310
311 sourcePos = sourceObj->getPos();
312 m_samplePos = sampleObj->getPos();
313}
314
315//----------------------------------------------------------------------------------------------
318
321
323std::shared_ptr<const Geometry::ReferenceFrame> Peak::getReferenceFrame() const { return m_inst->getReferenceFrame(); }
324
326int Peak::getRow() const { return m_row; }
327
332void Peak::setRow(int row) { m_row = row; }
333
335int Peak::getCol() const { return m_col; }
336
341void Peak::setCol(int col) { m_col = col; }
342
347const std::string &Peak::getBankName() const { return m_bankName; }
348
352void Peak::setBankName(std::string bankName) { this->m_bankName = std::move(bankName); }
353
354// -------------------------------------------------------------------------------------
358double Peak::getWavelength() const {
359 // Energy in J of the neutron
361 // v = sqrt(2.0 * E / m)
362 double velocity = sqrt(2.0 * energy / PhysicalConstants::NeutronMass);
363 // wavelength = h / mv
364 double wavelength = PhysicalConstants::h / (PhysicalConstants::NeutronMass * velocity);
365 // Return it in angstroms
366 return wavelength * 1e10;
367}
368
369// -------------------------------------------------------------------------------------
373double Peak::getTOF() const {
374 // First, get the neutron traveling distances
375 double L1 = this->getL1();
376 double L2 = this->getL2();
377 // Energy in J of the neutron
380 // v = sqrt(2 * E / m)
381 double vi = sqrt(2.0 * Ei / PhysicalConstants::NeutronMass);
382 double vf = sqrt(2.0 * Ef / PhysicalConstants::NeutronMass);
383 // Time of flight in seconds = distance / speed
384 double tof = L1 / vi + L2 / vf;
385 // Return in microsecond units
386 return tof * 1e6;
387}
388
389// -------------------------------------------------------------------------------------
391double Peak::getScattering() const {
392 // The detector is at 2 theta scattering angle
393 V3D beamDir = m_samplePos - sourcePos;
394 V3D detDir = detPos - m_samplePos;
395
396 return detDir.angle(beamDir);
397}
398
399// -------------------------------------------------------------------------------------
401double Peak::getAzimuthal() const {
402 // The detector is at 2 theta scattering angle
403 V3D detDir = detPos - m_samplePos;
404
405 return atan2(detDir.Y(), detDir.X());
406}
407
408// -------------------------------------------------------------------------------------
411 V3D detDir = detPos - m_samplePos;
412 detDir /= detDir.norm();
413 return getInverseGoniometerMatrix() * detDir;
414}
415
416// -------------------------------------------------------------------------------------
419 V3D beamDir = m_samplePos - sourcePos;
420 beamDir /= beamDir.norm();
421 return getInverseGoniometerMatrix() * beamDir * -1.0;
422}
423
424// -------------------------------------------------------------------------------------
426double Peak::getDSpacing() const {
427 // The detector is at 2 theta scattering angle
428 V3D beamDir = m_samplePos - sourcePos;
429 V3D detDir = detPos - m_samplePos;
430
431 double two_theta;
432 try {
433 two_theta = detDir.angle(beamDir);
434 } catch (std::runtime_error &) {
435 two_theta = 0.;
436 }
437
438 // In general case (2*pi/d)^2=k_i^2+k_f^2-2*k_i*k_f*cos(two_theta)
439 // E_i,f=k_i,f^2*hbar^2/(2 m)
442 2.0 * sqrt(getInitialEnergy() * getFinalEnergy()) * cos(two_theta));
443}
444
445//----------------------------------------------------------------------------------------------
452 // Normalized beam direction
453 V3D beamDir = m_samplePos - sourcePos;
454 beamDir /= beamDir.norm();
455 // Normalized detector direction
456 V3D detDir = (detPos - m_samplePos);
457 detDir /= detDir.norm();
458
459 // Energy in J of the neutron
461 // v = sqrt(2.0 * E / m)
462 double vi = sqrt(2.0 * ei / PhysicalConstants::NeutronMass);
463 // wavenumber = h_bar / mv
465 // in angstroms
466 wi *= 1e10;
467 // wavevector=1/wavenumber = 2pi/wavelength
468 double wvi = 1.0 / wi;
469 // Now calculate the wavevector of the scattered neutron
470 double wvf = (2.0 * M_PI) / this->getWavelength();
471 // And Q in the lab frame
472 // Default for ki-kf is positive
473 double qSign = 1.0;
474 if (m_convention == "Crystallography")
475 qSign = -1.0;
476 return (beamDir * wvi - detDir * wvf) * qSign;
477}
478
479//----------------------------------------------------------------------------------------------
483 V3D Qlab = this->getQLabFrame();
484 // Multiply by the inverse of the goniometer matrix to get the sample frame
485 V3D Qsample = getInverseGoniometerMatrix() * Qlab;
486 return Qsample;
487}
488
489//----------------------------------------------------------------------------------------------
502void Peak::setQSampleFrame(const Mantid::Kernel::V3D &QSampleFrame, std::optional<double> detectorDistance) {
503 V3D Qlab = getGoniometerMatrix() * QSampleFrame;
504 this->setQLabFrame(Qlab, detectorDistance);
505}
506
507//----------------------------------------------------------------------------------------------
523void Peak::setQLabFrame(const Mantid::Kernel::V3D &qLab, std::optional<double> detectorDistance) {
524 if (!this->m_inst) {
525 throw std::invalid_argument("Setting QLab without an instrument would lead "
526 "to an inconsistent state for the Peak");
527 }
528 // Clear out the detector = we can't know them
529 m_detectorID = -1;
530 detPos = V3D();
532 m_row = -1;
533 m_col = -1;
534 setBankName("None");
535
536 /* The q-vector direction of the peak is = goniometer * ub * hkl_vector
537 * The incident neutron wavevector is along the beam direction, ki = 1/wl
538 * (usually z, but referenceframe is definitive).
539 * In the inelastic convention, q = ki - kf.
540 * The final neutron wavector kf = -qx in x; -qy in y; and (-q.beam_dir+1/wl)
541 * in beam direction.
542 * AND: norm(kf) = norm(ki) = 2*pi/wavelength
543 * THEREFORE: 1/wl = norm(q)^2 / (2*q.beam_dir)
544 */
545 const double norm_q = qLab.norm();
546 if (norm_q == 0.0)
547 throw std::invalid_argument("Peak::setQLabFrame(): Q cannot be 0,0,0.");
548
549 std::shared_ptr<const ReferenceFrame> refFrame = this->m_inst->getReferenceFrame();
550 const V3D refBeamDir = refFrame->vecPointingAlongBeam();
551 // Default for ki-kf has -q
552 const double qSign = (m_convention != "Crystallography") ? 1.0 : -1.0;
553 const double qBeam = qLab.scalar_prod(refBeamDir) * qSign;
554
555 if (qBeam == 0.0)
556 throw std::invalid_argument("Peak::setQLabFrame(): Q cannot be 0 in the beam direction.");
557
558 const double one_over_wl = (norm_q * norm_q) / (2.0 * qBeam);
559 const double wl = (2.0 * M_PI) / one_over_wl;
560 if (wl < 0.0) {
561 std::ostringstream mess;
562 mess << "Peak::setQLabFrame(): Wavelength found was negative (" << wl << " Ang)! This Q is not physical.";
563 throw std::invalid_argument(mess.str());
564 }
565
566 // Save the wavelength
567 this->setWavelength(wl);
568
569 V3D detectorDir = -qLab * qSign;
570 detectorDir[refFrame->pointingAlongBeam()] = one_over_wl - qBeam;
571 detectorDir.normalize();
572
573 // Use the given detector distance to find the detector position.
574 if (detectorDistance.has_value()) {
575 detPos = m_samplePos + detectorDir * detectorDistance.value();
576 // We do not-update the detector as by manually setting the distance the
577 // client seems to know better.
578 } else {
579 // Find the detector
581 const bool found = findDetector(detectorDir, tracer);
582 if (!found) {
583 // This is important, so we ought to log when this fails to happen.
584 g_log.debug("Could not find detector after setting qLab via setQLab with "
585 "QLab : " +
586 qLab.toString());
587
588 detPos = getVirtualDetectorPosition(detectorDir);
589 }
590 }
591}
592
593V3D Peak::getVirtualDetectorPosition(const V3D &detectorDir) const {
594 const auto component = getInstrument()->getComponentByName("extended-detector-space");
595 if (!component) {
596 return detectorDir; // the best idea we have is just the direction
597 }
598 const auto object = std::dynamic_pointer_cast<const ObjComponent>(component);
599 const auto distance = object->shape()->distance(Geometry::Track(m_samplePos, detectorDir));
600 return detectorDir * distance;
601}
602
603double Peak::getValueByColName(std::string name) const {
604 std::transform(name.begin(), name.end(), name.begin(), ::tolower);
605 std::map<std::string, double> colVals = {
606 {"detid", double(m_detectorID)}, {"row", double(m_row)}, {"col", double(m_col)}};
607 auto it = colVals.find(name);
608 if (it != colVals.end())
609 return it->second;
610 else
612}
613
625 return findDetector(tracer);
626}
627
637 // Scattered beam direction
638 const V3D beam = normalize(detPos - m_samplePos);
639
640 return findDetector(beam, tracer);
641}
642
651 bool found = false;
652 // Create a ray tracer
653 tracer.traceFromSample(beam);
655 if (det) {
656 // Set the detector ID, the row, col, etc.
657 this->setDetectorID(det->getID());
658 // The old detector position is not more precise if it comes from
659 // FindPeaksMD
660 detPos = det->getPos();
661 found = true;
662 }
663 // Use tube-gap parameter in instrument parameter file to find peaks with
664 // center in gaps between tubes
665 else if (m_inst->hasParameter("tube-gap")) {
666 std::vector<double> gaps = m_inst->getNumberParameter("tube-gap", true);
667 if (!gaps.empty()) {
668 const auto gap = static_cast<double>(gaps.front());
669 // try adding and subtracting tube-gap in 3 q dimensions to see if you can
670 // find detectors on each side of tube gap
671 for (int i = 0; i < 3; i++) {
672 V3D gapDir;
673 gapDir[i] = gap;
674 V3D beam1 = beam + gapDir;
675 tracer.traceFromSample(normalize(beam1));
677 V3D beam2 = beam - gapDir;
678 tracer.traceFromSample(normalize(beam2));
680 if (det1 && det2) {
681 // compute the cosAngle to select the detector closes to beam
682 if (beam1.cosAngle(beam) > beam2.cosAngle(beam)) {
683 // det1 is closer, use det1
684 this->setDetectorID(static_cast<int>(det1->getID()));
685 detPos = det1->getPos();
686 } else {
687 // det2 is closer, let's use det2
688 this->setDetectorID(static_cast<int>(det2->getID()));
689 detPos = det2->getPos();
690 }
691 found = true;
692 break;
693 }
694 }
695 }
696 }
697 return found;
698}
699
700//----------------------------------------------------------------------------------------------
702double Peak::getFinalEnergy() const { return m_finalEnergy; }
703
705double Peak::getInitialEnergy() const { return m_initialEnergy; }
706
709
712void Peak::setFinalEnergy(double m_finalEnergy) { this->m_finalEnergy = m_finalEnergy; }
713
716void Peak::setInitialEnergy(double m_initialEnergy) { this->m_initialEnergy = m_initialEnergy; }
717
718// -------------------------------------------------------------------------------------
721
722// -------------------------------------------------------------------------------------
724double Peak::getL1() const { return (m_samplePos - sourcePos).norm(); }
725
726// -------------------------------------------------------------------------------------
728double Peak::getL2() const { return (detPos - m_samplePos).norm(); }
729
735Peak &Peak::operator=(const Peak &other) {
736 if (&other != this) {
737 BasePeak::operator=(other);
738 m_inst = other.m_inst;
739 m_det = other.m_det;
740 m_bankName = other.m_bankName;
741 m_row = other.m_row;
742 m_col = other.m_col;
743 m_detectorID = other.m_detectorID;
744 m_initialEnergy = other.m_initialEnergy;
745 m_finalEnergy = other.m_finalEnergy;
746 sourcePos = other.sourcePos;
747 m_samplePos = other.m_samplePos;
748 detPos = other.detPos;
749 m_detIDs = other.m_detIDs;
750 }
751 return *this;
752}
753
758
764 auto det = getDetector();
765 if (det == nullptr) {
766 throw Mantid::Kernel::Exception::NullPointerException("Peak", "Detector");
767 }
768 return getDetector()->getPos();
769}
770
772
773} // 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:213
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:131
Mantid::Kernel::Matrix< double > getGoniometerMatrix() const override
Get the goniometer rotation matrix at which this peak was measured.
Definition BasePeak.cpp:209
virtual double getValueByColName(std::string colName) const
Helper function for displaying/sorting peaks.
Definition BasePeak.cpp:249
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:335
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:502
Mantid::Kernel::V3D getSourceDirectionSampleFrame() const override
Calculate the reverse incident beam direction in the sample frame
Definition Peak.cpp:418
Geometry::Instrument_const_sptr getInstrument() const
Return a shared ptr to the instrument for this peak.
Definition Peak.cpp:320
Geometry::IDetector_const_sptr m_det
Detector pointed to.
Definition Peak.h:141
Peak()
Default constructor.
Definition Peak.cpp:31
double getDSpacing() const override
Calculate the d-spacing of the peak, in 1/Angstroms
Definition Peak.cpp:426
int m_row
Cached row in the detector.
Definition Peak.h:147
const std::set< int > & getContributingDetIDs() const
Return the set of detector IDs that contribute to this peak.
Definition Peak.cpp:286
void addContributingDetID(const int id)
Add a detector ID that contributed to this peak.
Definition Peak.cpp:272
static Mantid::Kernel::Logger g_log
Static logger.
Definition Peak.h:171
Mantid::Kernel::V3D getDetectorPosition() const
Forwarding function.
Definition Peak.cpp:763
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:326
std::set< int > m_detIDs
List of contributing detectors IDs.
Definition Peak.h:168
void setWavelength(double wavelength) override
Set the incident wavelength of the neutron.
Definition Peak.cpp:188
std::string m_bankName
Name of the parent bank.
Definition Peak.h:144
double getL1() const override
Return the L1 flight path length (source to sample), in meters.
Definition Peak.cpp:724
void removeContributingDetector(const int id)
Removes an ID from the list of contributing detectors.
Definition Peak.cpp:279
Mantid::Kernel::V3D detPos
Cached detector position.
Definition Peak.h:165
Peak & operator=(Peak &&) noexcept=default
double getInitialEnergy() const override
Get the initial (incident) neutron energy in meV.
Definition Peak.cpp:705
Mantid::Kernel::V3D getQLabFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
Definition Peak.cpp:451
void setRow(int row)
For RectangularDetectors only, sets the row (y) of the pixel of the detector.
Definition Peak.cpp:332
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:523
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:206
double m_initialEnergy
Initial energy of neutrons at the peak.
Definition Peak.h:156
void setBankName(std::string bankName)
Set the BankName of this peak.
Definition Peak.cpp:352
Geometry::Instrument_const_sptr m_inst
Shared pointer to the instrument (for calculating some values )
Definition Peak.h:138
double getEnergyTransfer() const override
Get the difference between the initial and final neutron energy in meV.
Definition Peak.cpp:708
int getDetectorID() const override
Get the ID of the detector at the center of the peak
Definition Peak.cpp:265
Mantid::Kernel::V3D sourcePos
Cached source position.
Definition Peak.h:162
double getAzimuthal() const override
Calculate the azimuthal angle of the peak
Definition Peak.cpp:401
int m_col
Cached column in the detector.
Definition Peak.h:150
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:623
Geometry::IDetector_const_sptr getDetector() const
Return a shared ptr to the detector at center of peak.
Definition Peak.cpp:317
Mantid::Kernel::V3D getDetectorDirectionSampleFrame() const override
Calculate the scattered beam direction in the sample frame
Definition Peak.cpp:410
void setInitialEnergy(double m_initialEnergy) override
Set the initial energy.
Definition Peak.cpp:716
double getFinalEnergy() const override
Get the final neutron energy in meV.
Definition Peak.cpp:702
Kernel::V3D getVirtualDetectorPosition(const Kernel::V3D &detectorDir) const
Get the approximate position of a peak that falls off the detectors.
Definition Peak.cpp:593
double getWavelength() const override
Calculate the neutron wavelength (in angstroms) at the peak (Note for inelastic scattering - it is th...
Definition Peak.cpp:358
void setCol(int col)
For RectangularDetectors only, sets the column (x) of the pixel of the detector.
Definition Peak.cpp:341
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:373
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:323
virtual Mantid::Kernel::V3D getDetPos() const
Return the detector position vector.
Definition Peak.cpp:720
Mantid::Kernel::V3D getQSampleFrame() const override
Return the Q change (of the lattice, k_i - k_f) for this peak.
Definition Peak.cpp:482
double getL2() const override
Return the L2 flight path length (sample to detector), in meters.
Definition Peak.cpp:728
const std::string & getBankName() const
Find the name of the bank that is the parent of the detector.
Definition Peak.cpp:347
void setInstrument(const Geometry::Instrument_const_sptr &inst)
Set the instrument (and save the source/sample pos).
Definition Peak.cpp:294
void setFinalEnergy(double m_finalEnergy) override
Set the final energy.
Definition Peak.cpp:712
double getScattering() const override
Calculate the scattering angle of the peak
Definition Peak.cpp:391
double getValueByColName(std::string colName) const override
Helper function for displaying/sorting peaks.
Definition Peak.cpp:603
Mantid::Kernel::V3D getDetectorPositionNoCheck() const
Forwarding function.
Definition Peak.cpp:757
double m_finalEnergy
Final energy of the neutrons at peak (normally same as m_InitialEnergy)
Definition Peak.h:159
int m_detectorID
ID of the detector.
Definition Peak.h:153
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...
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:51
void debug(const std::string &msg)
Logs at debug level.
Definition Logger.cpp:145
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:280
constexpr double X() const noexcept
Get x.
Definition V3D.h:238
double normalize()
Make a normalized vector (return norm value)
Definition V3D.cpp:129
constexpr double Y() const noexcept
Get y.
Definition V3D.h:239
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:269
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:167
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:232
MANTID_KERNEL_DLL V3D normalize(V3D v)
Normalizes a V3D.
Definition V3D.h:352
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.