16#include "MantidNexus/NexusFile.h"
36 setNumberOfDetectorGroups(0);
45 :
IPeaksWorkspace(other), m_peaks(other.m_peaks), m_columns(), m_columnNames(), m_coordSystem(other.m_coordSystem) {
68 const auto &col =
name.first;
69 const bool ascending =
name.second;
70 bool lessThan =
false;
77 lessThan = (valA < valB);
117 if (peakNum >=
static_cast<int>(
m_peaks.size()) || peakNum < 0) {
118 throw std::invalid_argument(
"LeanElasticPeaksWorkspace::removePeak(): peakNum is out of range.");
127 if (badPeaks.empty())
134 return std::any_of(badPeaks.cbegin(), badPeaks.cend(), [ip](int badPeak) { return badPeak == ip; });
136 m_peaks.erase(it, m_peaks.end());
173 if (peakNum >=
m_peaks.size()) {
174 throw std::invalid_argument(
"LeanElasticPeaksWorkspace::getPeak(): peakNum is out of range.");
185 if (peakNum >=
m_peaks.size()) {
186 throw std::invalid_argument(
"LeanElasticPeaksWorkspace::getPeak(): peakNum is out of range.");
199 std::optional<double>)
const {
210std::unique_ptr<Geometry::IPeak>
230 std::unique_ptr<IPeak> peak = std::make_unique<LeanElasticPeak>(
position,
run().getGoniometer().getR());
271 const V3D qSampleFrame = lattice.getUB() *
HKL * 2 * M_PI;
274 std::unique_ptr<IPeak> peak = std::make_unique<LeanElasticPeak>(qSampleFrame, goniometer.getR());
277 peak->setIntHKL(peak->getHKL());
322 const std::string peaksIntegrated =
"PeaksIntegrated";
323 if (this->
run().hasProperty(peaksIntegrated)) {
324 const auto value = boost::lexical_cast<int>(this->
run().getProperty(peaksIntegrated)->
value());
383 for (
size_t i = 0; i <
m_columns.size(); i++)
386 throw std::invalid_argument(
"Column named " +
name +
" was not found in the LeanElasticPeaksWorkspace.");
393 throw std::invalid_argument(
"LeanElasticPeaksWorkspace::getColumn() called with invalid index.");
401 throw std::invalid_argument(
"LeanElasticPeaksWorkspace::getColumn() called with invalid index.");
408 const size_t np(
m_peaks.size());
411 std::vector<double> H(np);
412 std::vector<double> K(np);
413 std::vector<double> L(np);
414 std::vector<double> intensity(np);
415 std::vector<double> sigmaIntensity(np);
416 std::vector<double> binCount(np);
417 std::vector<double> waveLength(np);
418 std::vector<double> scattering(np);
419 std::vector<double> dSpacing(np);
420 std::vector<int> runNumber(np);
421 std::vector<int> peakNumber(np);
422 std::vector<double> tbar(np);
423 std::vector<double> intHKL(3 * np);
424 std::vector<double> intMNP(3 * np);
425 std::vector<double> goniometerMatrix(9 * np);
426 std::vector<std::string> shapes(np);
427 std::vector<double> qlabs(3 * np);
428 std::vector<double> monitorCount(np);
431 size_t maxShapeJSONLength = 0;
432 for (
size_t i = 0; i < np; i++) {
448 intHKL[3 * i + 0] = hkl[0];
449 intHKL[3 * i + 1] = hkl[1];
450 intHKL[3 * i + 2] = hkl[2];
452 intMNP[3 * i + 0] = mnp[0];
453 intMNP[3 * i + 1] = mnp[1];
454 intMNP[3 * i + 2] = mnp[2];
456 goniometerMatrix[9 * i + 0] = gm[0][0];
457 goniometerMatrix[9 * i + 1] = gm[1][0];
458 goniometerMatrix[9 * i + 2] = gm[2][0];
459 goniometerMatrix[9 * i + 3] = gm[0][1];
460 goniometerMatrix[9 * i + 4] = gm[1][1];
461 goniometerMatrix[9 * i + 5] = gm[2][1];
462 goniometerMatrix[9 * i + 6] = gm[0][2];
463 goniometerMatrix[9 * i + 7] = gm[1][2];
464 goniometerMatrix[9 * i + 8] = gm[2][2];
467 shapes[i] = shapeJSON;
468 if (shapeJSON.size() > maxShapeJSONLength) {
469 maxShapeJSONLength = shapeJSON.size();
480 const std::string specifyInteger =
"An integer";
481 const std::string specifyDouble =
"A double";
482 const std::string specifyString =
"A string";
483 file->makeGroup(
"peaks_workspace",
"NXentry",
487 file->writeData(
"coordinate_system",
static_cast<uint32_t
>(
m_coordSystem));
492 file->putAttr(
"QConvention", m_QConvention);
495 file->writeData(
"column_1", H);
496 file->openData(
"column_1");
497 file->putAttr(
"name",
"H");
498 file->putAttr(
"interpret_as", specifyDouble);
499 file->putAttr(
"units",
"Not known");
503 file->writeData(
"column_2", K);
504 file->openData(
"column_2");
505 file->putAttr(
"name",
"K");
506 file->putAttr(
"interpret_as", specifyDouble);
507 file->putAttr(
"units",
"Not known");
511 file->writeData(
"column_3", L);
512 file->openData(
"column_3");
513 file->putAttr(
"name",
"L");
514 file->putAttr(
"interpret_as", specifyDouble);
515 file->putAttr(
"units",
"Not known");
519 file->writeData(
"column_4", intensity);
520 file->openData(
"column_4");
521 file->putAttr(
"name",
"Intensity");
522 file->putAttr(
"interpret_as", specifyDouble);
523 file->putAttr(
"units",
"Not known");
527 file->writeData(
"column_5", sigmaIntensity);
528 file->openData(
"column_5");
529 file->putAttr(
"name",
"Sigma Intensity");
530 file->putAttr(
"interpret_as", specifyDouble);
531 file->putAttr(
"units",
"Not known");
535 file->writeData(
"column_6", binCount);
536 file->openData(
"column_6");
537 file->putAttr(
"name",
"Bin Count");
538 file->putAttr(
"interpret_as", specifyDouble);
539 file->putAttr(
"units",
"Not known");
543 file->writeData(
"column_7", waveLength);
544 file->openData(
"column_7");
545 file->putAttr(
"name",
"Wave Length");
546 file->putAttr(
"interpret_as", specifyDouble);
547 file->putAttr(
"units",
"Not known");
551 file->writeData(
"column_8", scattering);
552 file->openData(
"column_8");
553 file->putAttr(
"name",
"Scattering");
554 file->putAttr(
"interpret_as", specifyDouble);
555 file->putAttr(
"units",
"Not known");
559 file->writeData(
"column_9", dSpacing);
560 file->openData(
"column_9");
561 file->putAttr(
"name",
"D Spacing");
562 file->putAttr(
"interpret_as", specifyDouble);
563 file->putAttr(
"units",
"Not known");
567 file->writeData(
"column_10", runNumber);
568 file->openData(
"column_10");
569 file->putAttr(
"name",
"Run Number");
570 file->putAttr(
"interpret_as", specifyInteger);
571 file->putAttr(
"units",
"Not known");
575 file->writeData(
"column_11", peakNumber);
576 file->openData(
"column_11");
577 file->putAttr(
"name",
"Peak Number");
578 file->putAttr(
"interpret_as", specifyInteger);
579 file->putAttr(
"units",
"Not known");
583 file->writeData(
"column_12", tbar);
584 file->openData(
"column_12");
585 file->putAttr(
"name",
"TBar");
586 file->putAttr(
"interpret_as", specifyDouble);
587 file->putAttr(
"units",
"Not known");
592 file->writeData(
"column_13", goniometerMatrix, array_dims);
593 file->openData(
"column_13");
594 file->putAttr(
"name",
"Goniometer Matrix");
595 file->putAttr(
"interpret_as",
"A matrix of 3x3 doubles");
596 file->putAttr(
"units",
"Not known");
601 dims.emplace_back(np);
602 dims.emplace_back(
static_cast<int>(maxShapeJSONLength));
603 const std::string
name =
"column_14";
605 file->openData(
name);
607 auto toNexus =
new char[maxShapeJSONLength * np];
608 for (
size_t ii = 0; ii < np; ii++) {
609 std::string rowStr = shapes[ii];
610 for (
size_t ic = 0; ic < rowStr.size(); ic++)
611 toNexus[ii * maxShapeJSONLength + ic] = rowStr[ic];
612 for (
size_t ic = rowStr.size(); ic < static_cast<size_t>(maxShapeJSONLength); ic++)
613 toNexus[ii * maxShapeJSONLength + ic] =
' ';
616 file->putData(toNexus);
619 file->putAttr(
"units",
"Not known");
620 file->putAttr(
"name",
"Shape");
621 file->putAttr(
"interpret_as", specifyString);
626 file->writeData(
"column_15", qlabs, qlab_dims);
627 file->openData(
"column_15");
628 file->putAttr(
"name",
"Q LabFrame");
629 file->putAttr(
"interpret_as",
"A vector of 3 doubles");
630 file->putAttr(
"units",
"angstrom^-1");
634 file->writeData(
"column_16", intHKL, qlab_dims);
635 file->openData(
"column_16");
636 file->putAttr(
"name",
"IntHKL");
637 file->putAttr(
"interpret_as",
"A vector of 3 doubles");
638 file->putAttr(
"units",
"r.l.u.");
642 file->writeData(
"column_17", intMNP, qlab_dims);
643 file->openData(
"column_17");
644 file->putAttr(
"name",
"IntMNP");
645 file->putAttr(
"interpret_as",
"A vector of 3 doubles");
646 file->putAttr(
"units",
"r.l.u.");
650 file->writeData(
"column_18", monitorCount);
651 file->openData(
"column_18");
652 file->putAttr(
"name",
"Monitor Count");
653 file->putAttr(
"interpret_as", specifyDouble);
654 file->putAttr(
"units",
"Not known");
700IPropertyManager::getValue<Mantid::DataObjects::LeanElasticPeaksWorkspace_sptr>(
const std::string &
name)
const {
702 getPointerToProperty(
name));
706 std::string message =
707 "Attempt to assign property " +
name +
" to incorrect type. Expected shared_ptr<LeanElasticPeaksWorkspace>.";
708 throw std::runtime_error(message);
714IPropertyManager::getValue<Mantid::DataObjects::LeanElasticPeaksWorkspace_const_sptr>(
const std::string &
name)
const {
716 getPointerToProperty(
name))) {
717 return prop->operator()();
719 std::string message =
"Attempt to assign property " +
name +
720 " to incorrect type. Expected const "
721 "shared_ptr<LeanElasticPeaksWorkspace>.";
722 throw std::runtime_error(message);
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
#define DECLARE_WORKSPACE(classname)
Run & mutableRun()
Writable version of the run object.
const Run & run() const
Run details object access.
const Sample & sample() const
Sample accessors.
int getRunNumber() const
Utility method to get the run number.
void setNumberOfDetectorGroups(const size_t count) const
Sets the number of detector groups.
Interface to the class Mantid::DataObjects::PeaksWorkspace.
ITableWorkspace is an implementation of Workspace in which the data are organised in columns of same ...
This class contains the information about the log entries.
const Geometry::Goniometer & getGoniometer() const
Return reference to the first const Goniometer object for this run.
const Geometry::OrientedLattice & getOrientedLattice() const
Get a reference to the sample's OrientedLattice.
Mantid::Kernel::V3D getIntMNP() const override
Return the int MNP vector.
double getL() const override
Get the L index of the peak.
double getIntensity() const override
Return the integrated peak intensity.
double getAbsorptionWeightedPathLength() const override
Gets the absorption weighted path length.
double getSigmaIntensity() const override
Return the error on the integrated peak intensity.
double getK() const override
Get the K index of the peak.
int getPeakNumber() const override
Returns the unique peak number Returns -1 if it could not find it.
int getRunNumber() const override
Return the run number this peak was measured at.
double getH() const override
Get the H index of the peak.
double getBinCount() const override
Return the # of counts in the bin at its peak.
Mantid::Kernel::Matrix< double > getGoniometerMatrix() const override
Get the goniometer rotation matrix at which this peak was measured.
const Mantid::Geometry::PeakShape & getPeakShape() const override
Get the peak shape.
double getMonitorCount() const override
Return the monitor count stored in this peak.
Mantid::Kernel::V3D getIntHKL() const override
Return the int HKL vector.
virtual double getValueByColName(std::string colName) const
Helper function for displaying/sorting peaks.
Structure describing a single-crystal peak.
double getWavelength() const override
Return the neutron wavelength (in angstroms)
double getScattering() const override
Calculate the scattering angle of the peak
double getDSpacing() const override
Calculate the d-spacing of the peak, in 1/Angstroms
Mantid::Kernel::V3D getQLabFrame() const final
Return the Q change (of the lattice, k_i - k_f) for this peak.
The class LeanElasticPeaksWorkspace stores information about a set of SCD lean peaks.
int peakInfoNumber(const Kernel::V3D &qFrame, bool labCoords) const override
Returns selected information for a "peak" at QLabFrame.
std::unique_ptr< Geometry::IPeak > createPeakQSample(const Kernel::V3D &position) const override
Creates an instance of a Peak BUT DOES NOT ADD IT TO THE WORKSPACE.
bool hasIntegratedPeaks() const override
Getter for the integration status.
API::ITableWorkspace_sptr createDetectorTable() const override
Creates a new TableWorkspace giving the IDs of the detectors that contribute to the peaks within the ...
std::unique_ptr< Geometry::IPeak > createPeak() const override
Create a Peak using default values.
void initColumns()
Initialize the table structure.
std::vector< std::pair< std::string, std::string > > peakInfo(const Kernel::V3D &qFrame, bool labCoords) const override
Returns selected information for a "peak" at QLabFrame.
std::shared_ptr< Mantid::API::Column > getColumn(const std::string &name) override
Gets the shared pointer to a column by name.
API::LogManager_sptr logs() override
Get access to shared pointer containing workspace porperties.
void setCoordinateSystem(const Kernel::SpecialCoordinateSystem coordinateSystem) override
Set the special coordinate system.
int getNumberPeaks() const override
Kernel::SpecialCoordinateSystem m_coordSystem
Coordinates.
void sort(std::vector< ColumnAndDirection > &criteria) override
Sort the peaks by one or more criteria.
std::vector< std::string > m_columnNames
Column names.
void removePeak(int peakNum) override
Removes the indicated peak.
void saveNexus(Nexus::File *file) const override
void removePeaks(std::vector< int > badPeaks) override
Removes multiple peaks.
size_t getMemorySize() const override
Return the memory used in bytes.
std::vector< std::shared_ptr< Mantid::DataObjects::PeakColumn< LeanElasticPeak > > > m_columns
Column shared pointers.
void addPeak(const Geometry::IPeak &peak) override
Add a peak to the list.
std::vector< LeanElasticPeak > m_peaks
Vector of Peak contained within.
std::unique_ptr< Geometry::IPeak > createPeakHKL(const Kernel::V3D &HKL) const override
Create a Peak from a HKL value provided by the client.
LeanElasticPeaksWorkspace()
Register the workspace as a type.
API::LogManager_const_sptr getLogs() const override
Get constant access to shared pointer containing workspace porperties; Copies logs into new LogManage...
LeanElasticPeak & getPeak(size_t const peakNum) override
Return a reference to the Peak.
std::pair< std::string, bool > ColumnAndDirection
std::vector< LeanElasticPeak > & getPeaks()
Return a reference to the Peaks vector.
ITableWorkspace * doCloneColumns(const std::vector< std::string > &colNames) const override
Kernel::SpecialCoordinateSystem getSpecialCoordinateSystem() const override
Get the special coordinate system.
virtual size_t getColumnIndex(const std::string &name) const
std::string getConvention() const override
void addPeakColumn(const std::string &name)
Adds a new PeakColumn of the given type.
PeakColumn : a Column sub-class used to display peak information as a TableWorkspace.
Comparator class for sorting peaks by one or more criteria.
PeakComparator(std::vector< ColumnAndDirection > &criteria)
Constructor for the comparator for sorting peaks.
LeanElasticPeaksWorkspace::ColumnAndDirection ColumnAndDirection
bool operator()(const LeanElasticPeak &a, const LeanElasticPeak &b)
Compare two peaks using the stored criteria.
std::vector< ColumnAndDirection > & criteria
Structure describing a single-crystal peak.
virtual std::string toJSON() const =0
Serialize.
Marks code as not implemented yet.
The concrete, templated class for properties.
constexpr double X() const noexcept
Get x.
constexpr double Y() const noexcept
Get y.
constexpr double Z() const noexcept
Get z.
static unsigned short constexpr CHAR
std::shared_ptr< const LogManager > LogManager_const_sptr
shared pointer to the logManager base class (const version)
std::shared_ptr< LogManager > LogManager_sptr
shared pointer to the logManager base class
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< LeanElasticPeaksWorkspace > LeanElasticPeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< const LeanElasticPeaksWorkspace > LeanElasticPeaksWorkspace_const_sptr
Typedef for a shared pointer to a const peaks workspace.
SpecialCoordinateSystem
Special coordinate systems for Q3D.
std::vector< dimsize_t > DimVector