Commit 18f8bc65 authored by Lynch, Vickie's avatar Lynch, Vickie
Browse files

Refs #12863 New branch with all commits

parent 47e00fc3
#include "MantidAPI/IMDWorkspace.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/IPropertyManager.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/VMD.h"
#include <sstream>
......@@ -88,6 +89,14 @@ const std::string IMDWorkspace::toString() const {
os << "Binned from '" << getOriginalWorkspace()->getName();
}
os << "\n";
std::string convention =
Kernel::ConfigService::Instance().getString("Q.convention");
if (convention == "Crystallography")
os << "Crystallography: ki-kf";
else
os << "Inelastic: kf-ki";
os << "\n";
return os.str();
}
......
......@@ -379,7 +379,10 @@ void MDGeometry::transformDimensions(std::vector<double> &scaling,
static_cast<coord_t>(offset[d]);
coord_t max = (dim->getMaximum() * static_cast<coord_t>(scaling[d])) +
static_cast<coord_t>(offset[d]);
dim->setRange(dim->getNBins(), min, max);
if (min < max)
dim->setRange(dim->getNBins(), min, max);
else
dim->setRange(dim->getNBins(), max, min);
}
// Clear the original workspace
setOriginalWorkspace(boost::shared_ptr<Workspace>());
......
......@@ -59,7 +59,7 @@ private:
/// Read a single peak from peaks file
DataObjects::Peak readPeak(DataObjects::PeaksWorkspace_sptr outWS,
std::string &lastStr, std::ifstream &in,
int &seqNum, std::string bankName);
int &seqNum, std::string bankName, double qSign);
int findPixelID(Geometry::Instrument_const_sptr inst, std::string bankName,
int col, int row);
......
......@@ -33,9 +33,11 @@ LoadHKL::~LoadHKL() {}
/** Initialize the algorithm's properties.
*/
void LoadHKL::init() {
declareProperty(
new FileProperty("Filename", "", FileProperty::Load, {".hkl"}),
"Path to an hkl file to save.");
std::vector<std::string> exts;
exts.push_back(".hkl");
declareProperty(new FileProperty("Filename", "", FileProperty::Load, exts),
"Path to an hkl file to save.");
declareProperty(new WorkspaceProperty<PeaksWorkspace>("OutputWorkspace", "",
Direction::Output),
......@@ -58,6 +60,11 @@ void LoadHKL::exec() {
// % (H, K, L, FSQ, SIGFSQ, hstnum, WL, TBAR, CURHST, SEQNUM, TRANSMISSION,
// DN, TWOTH, DSP))
// HKL is flipped by -1 due to different q convention in ISAW vs mantid.
// Default for kf-ki has -q
double qSign = -1.0;
std::string convention = ConfigService::Instance().getString("Q.convention");
if (convention == "Crystallography")
qSign = 1.0;
Instrument_sptr inst(new Geometry::Instrument);
Detector *detector = new Detector("det1", -1, 0);
detector->setPos(0.0, 0.0, 0.0);
......@@ -105,7 +112,7 @@ void LoadHKL::exec() {
}
Peak peak(inst, scattering, wl);
peak.setHKL(-h, -k, -l);
peak.setHKL(qSign * h, qSign * k, qSign * l);
peak.setIntensity(Inti);
peak.setSigmaIntensity(SigI);
peak.setRunNumber(run);
......
......@@ -328,12 +328,13 @@ std::string LoadIsawPeaks::readHeader(PeaksWorkspace_sptr outWS,
* @param in :: input stream
* @param seqNum [out] :: the sequence number of the peak
* @param bankName :: the bank number from the ISAW file.
* @param qSign :: For inelastic this is 1; for crystallography this is -1
* @return the Peak the Peak object created
*/
DataObjects::Peak LoadIsawPeaks::readPeak(PeaksWorkspace_sptr outWS,
std::string &lastStr,
std::ifstream &in, int &seqNum,
std::string bankName) {
std::string bankName, double qSign) {
double h;
double k;
double l;
......@@ -406,8 +407,7 @@ DataObjects::Peak LoadIsawPeaks::readPeak(PeaksWorkspace_sptr outWS,
// Create the peak object
Peak peak(outWS->getInstrument(), pixelID, wl);
// HKL's are flipped by -1 because of the internal Q convention
peak.setHKL(-h, -k, -l);
peak.setHKL(qSign * h, qSign * k, qSign * l);
peak.setIntensity(Inti);
peak.setSigmaIntensity(SigI);
peak.setBinCount(IPK);
......@@ -504,7 +504,12 @@ std::string LoadIsawPeaks::readPeakBlockHeader(std::string lastStr,
*/
void LoadIsawPeaks::appendFile(PeaksWorkspace_sptr outWS,
std::string filename) {
// HKL's are flipped by -1 because of the internal Q convention
// unless Crystallography convention
double qSign = -1.0;
std::string convention = ConfigService::Instance().getString("Q.convention");
if (convention == "Crystallography")
qSign = 1.0;
// Open the file
std::ifstream in(filename.c_str());
......@@ -564,7 +569,7 @@ void LoadIsawPeaks::appendFile(PeaksWorkspace_sptr outWS,
try {
// Read the peak
Peak peak = readPeak(outWS, s, in, seqNum, bankName);
Peak peak = readPeak(outWS, s, in, seqNum, bankName, qSign);
// Get the calculated goniometer matrix
Matrix<double> gonMat = uniGonio.getR();
......
......@@ -126,6 +126,12 @@ void SaveHKL::exec() {
int runSequence = 0;
int bankold = -1;
int runold = -1;
// HKL is flipped by -1 due to different q convention in ISAW vs mantid.
// Default for kf-ki has -q
double qSign = -1.0;
std::string convention = ConfigService::Instance().getString("Q.convention");
if (convention == "Crystallography")
qSign = 1.0;
std::fstream out;
bool append = getProperty("AppendFile");
......@@ -308,14 +314,14 @@ void SaveHKL::exec() {
// hklFile.write('%4d%4d%4d%8.2f%8.2f%4d%8.4f%7.4f%7d%7d%7.4f%4d%9.5f%9.4f\n'
// % (H, K, L, FSQ, SIGFSQ, hstnum, WL, TBAR, CURHST, SEQNUM,
// TRANSMISSION, DN, TWOTH, DSP))
// HKL is flipped by -1 due to different q convention in ISAW vs mantid.
if (p.getH() == 0 && p.getK() == 0 && p.getL() == 0) {
banned.push_back(wi);
continue;
}
if (decimalHKL == EMPTY_INT())
out << std::setw(4) << Utils::round(-p.getH()) << std::setw(4)
<< Utils::round(-p.getK()) << std::setw(4) << Utils::round(-p.getL());
out << std::setw(4) << Utils::round(qSign * p.getH()) << std::setw(4)
<< Utils::round(qSign * p.getK()) << std::setw(4)
<< Utils::round(qSign * p.getL());
else
out << std::setw(5 + decimalHKL) << std::fixed
<< std::setprecision(decimalHKL) << -p.getH()
......
......@@ -247,7 +247,12 @@ void SaveIsawPeaks::exec() {
}
}
}
// HKL's are flipped by -1 because of the internal Q convention
// unless Crystallography convention
double qSign = -1.0;
std::string convention = ConfigService::Instance().getString("Q.convention");
if (convention == "Crystallography")
qSign = 1.0;
// ============================== Save all Peaks
// =========================================
// Sequence number
......@@ -305,11 +310,11 @@ void SaveIsawPeaks::exec() {
// Sequence (run) number
out << "3" << std::setw(7) << seqNum;
// HKL is flipped by -1 due to different q convention in ISAW vs
// mantid.
out << std::setw(5) << Utils::round(-p.getH()) << std::setw(5)
<< Utils::round(-p.getK()) << std::setw(5)
<< Utils::round(-p.getL());
// HKL's are flipped by -1 because of the internal Q convention
// unless Crystallography convention
out << std::setw(5) << Utils::round(qSign * p.getH()) << std::setw(5)
<< Utils::round(qSign * p.getK()) << std::setw(5)
<< Utils::round(qSign * p.getL());
// Row/column
out << std::setw(8) << std::fixed << std::setprecision(2)
......
......@@ -111,6 +111,12 @@ void SaveLauenorm::exec() {
// ============================== Save all Peaks
// =========================================
// HKL is flipped by -1 due to different q convention in ISAW vs mantid.
// Default for kf-ki has -q
double qSign = -1.0;
std::string convention = ConfigService::Instance().getString("Q.convention");
if (convention == "Crystallography")
qSign = 1.0;
// Go through each peak at this run / bank
for (int wi = 0; wi < ws->getNumberPeaks(); wi++) {
......@@ -170,10 +176,12 @@ void SaveLauenorm::exec() {
// h k l lambda theta intensity and sig(intensity) in format
// (3I5,2F10.5,2I10)
// HKL is flipped by -1 due to different q convention in ISAW vs mantid.
// unless Crystallography convention
if (p.getH() == 0 && p.getK() == 0 && p.getL() == 0)
continue;
out << std::setw(5) << Utils::round(-p.getH()) << std::setw(5)
<< Utils::round(-p.getK()) << std::setw(5) << Utils::round(-p.getL());
out << std::setw(5) << Utils::round(qSign * p.getH()) << std::setw(5)
<< Utils::round(qSign * p.getK()) << std::setw(5)
<< Utils::round(qSign * p.getL());
out << std::setw(10) << std::fixed << std::setprecision(5) << lambda;
// Assume that want theta not two-theta
out << std::setw(10) << std::fixed << std::setprecision(5)
......
......@@ -1071,6 +1071,14 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) {
// peaks_workspace
m_cppFile->closeGroup();
// HKL is flipped by -1 due to different q convention in Crystallography.
// Always write out in ki-kf so consistent with old files
double qSign = 1.0;
std::string convention =
ConfigService::Instance().getString("default.convention");
if (convention == "Crystallography")
qSign = -1.0;
for (int r = 0; r < numberPeaks; r++) {
Kernel::V3D v3d;
v3d[2] = 1.0;
......@@ -1097,7 +1105,7 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) {
nxDouble.load();
for (int r = 0; r < numberPeaks; r++) {
double val = nxDouble[r];
double val = qSign * nxDouble[r];
peakWS->getPeak(r).setH(val);
}
}
......@@ -1107,7 +1115,7 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) {
nxDouble.load();
for (int r = 0; r < numberPeaks; r++) {
double val = nxDouble[r];
double val = qSign * nxDouble[r];
peakWS->getPeak(r).setK(val);
}
}
......@@ -1117,7 +1125,7 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) {
nxDouble.load();
for (int r = 0; r < numberPeaks; r++) {
double val = nxDouble[r];
double val = qSign * nxDouble[r];
peakWS->getPeak(r).setL(val);
}
}
......@@ -1629,20 +1637,11 @@ void LoadNexusProcessed::readInstrumentGroup(
// Now build the spectra list
int index = 0;
bool haveSpectraAxis = local_workspace->getAxis(1)->isSpectra();
for (int i = 1; i <= spectraInfo.nSpectra; ++i) {
int spectrum(-1);
// prefer the spectra number from the instrument section
// over anything else. If not there then use a spectra axis
// number if we have one, else make one up as nothing was
// written to the file. We should always set it so that
// CompareWorkspaces gives the expected answer on a Save/Load
// round trip.
if (spectraInfo.hasSpectra) {
spectrum = spectraInfo.spectraNumbers[i - 1];
} else if (haveSpectraAxis && !m_axis1vals.empty()) {
spectrum = static_cast<specid_t>(m_axis1vals[i - 1]);
} else {
spectrum = i + 1;
}
......@@ -1652,7 +1651,11 @@ void LoadNexusProcessed::readInstrumentGroup(
find(m_spec_list.begin(), m_spec_list.end(), i) !=
m_spec_list.end())) {
ISpectrum *spec = local_workspace->getSpectrum(index);
spec->setSpectrumNo(spectrum);
if (m_axis1vals.empty()) {
spec->setSpectrumNo(spectrum);
} else {
spec->setSpectrumNo(static_cast<specid_t>(m_axis1vals[i - 1]));
}
++index;
int start = spectraInfo.detectorIndex[i - 1];
......
......@@ -690,6 +690,7 @@ TMDE(void MDBox)::centroidSphere(Mantid::API::CoordTransform &radiusTransform,
TMDE(void MDBox)::transformDimensions(std::vector<double> &scaling,
std::vector<double> &offset) {
MDBoxBase<MDE, nd>::transformDimensions(scaling, offset);
this->calculateCentroid(this->m_centroid);
std::vector<MDE> &events = this->getEvents();
typename std::vector<MDE>::iterator it;
typename std::vector<MDE>::iterator it_end = events.end();
......
......@@ -16,6 +16,8 @@
#include "MantidDataObjects/MDFramesToSpecialCoordinateSystem.h"
#include "MantidDataObjects/MDGridBox.h"
#include "MantidDataObjects/MDLeanEvent.h"
#include "MantidKernel/ConfigService.h"
#include <iomanip>
#include <functional>
#include <algorithm>
......@@ -327,6 +329,7 @@ TMDE(signal_t MDEventWorkspace)::getSignalWithMaskAtCoord(
}
// Check if masked
const API::IMDNode *box = data->getBoxAtCoord(coords);
if (!box) return MDMaskValue;
if (box->getIsMasked()) {
return MDMaskValue;
}
......@@ -376,6 +379,7 @@ TMDE(std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>>
TMDE(std::vector<std::string> MDEventWorkspace)::getBoxControllerStats() const {
std::vector<std::string> out;
std::ostringstream mess;
size_t mem;
mem = (this->m_BoxController->getTotalNumMDBoxes() * sizeof(MDBox<MDE, nd>)) /
1024;
......
......@@ -9,6 +9,7 @@
#include "MantidKernel/PhysicalConstants.h"
#include "MantidKernel/System.h"
#include "MantidGeometry/Crystal/PeakShape.h"
#include "MantidKernel/ConfigService.h"
#include <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
......@@ -214,6 +215,10 @@ private:
/// Static logger
static Mantid::Kernel::Logger g_log;
// ki-kf for Inelastic convention; kf-ki for Crystallography convention
std::string convention =
Kernel::ConfigService::Instance().getString("Q.convention");
};
} // namespace Mantid
......
......@@ -749,6 +749,12 @@ void MDBoxFlatTree::saveWSGenericInfo(::NeXus::File *const file,
file->writeData("coordinate_system",
static_cast<uint32_t>(ws->getSpecialCoordinateSystem()));
// Write out the Qconvention
// ki-kf for Inelastic convention; kf-ki for Crystallography convention
std::string m_QConvention =
Kernel::ConfigService::Instance().getString("Q.convention");
file->writeData("QConvention", m_QConvention);
// Write out the set display normalization
file->writeData("visual_normalization",
static_cast<uint32_t>(ws->displayNormalization()));
......@@ -808,6 +814,8 @@ void MDBoxFlatTree::saveAffineTransformMatricies(
void MDBoxFlatTree::saveAffineTransformMatrix(
::NeXus::File *const file, API::CoordTransform const *transform,
std::string entry_name) {
if (!transform)
return;
Kernel::Matrix<coord_t> matrix = transform->makeAffineMatrix();
g_log.debug() << "TRFM: " << matrix.str() << std::endl;
saveMatrix<coord_t>(file, entry_name, matrix, ::NeXus::FLOAT32,
......
......@@ -452,7 +452,11 @@ Mantid::Kernel::V3D Peak::getQLabFrame() const {
// Now calculate the wavevector of the scattered neutron
double wvf = (2.0 * M_PI) / this->getWavelength();
// And Q in the lab frame
return beamDir * wvi - detDir * wvf;
// Default for ki-kf is positive
double qSign = 1.0;
if (convention == "Crystallography")
qSign = -1.0;
return (beamDir * wvi - detDir * wvf) * qSign;
}
//----------------------------------------------------------------------------------------------
......@@ -528,7 +532,11 @@ void Peak::setQLabFrame(Mantid::Kernel::V3D QLabFrame,
boost::shared_ptr<const ReferenceFrame> refFrame =
this->m_inst->getReferenceFrame();
const V3D refBeamDir = refFrame->vecPointingAlongBeam();
const double qBeam = q.scalar_prod(refBeamDir);
// Default for ki-kf has -q
double qSign = 1.0;
if (convention == "Crystallography")
qSign = -1.0;
const double qBeam = q.scalar_prod(refBeamDir) * qSign;
if (norm_q == 0.0)
throw std::invalid_argument("Peak::setQLabFrame(): Q cannot be 0,0,0.");
......@@ -548,7 +556,12 @@ void Peak::setQLabFrame(Mantid::Kernel::V3D QLabFrame,
// Save the wavelength
this->setWavelength(wl);
V3D detectorDir = q * -1.0;
// Default for ki-kf has -q
qSign = -1.0;
if (convention == "Crystallography")
qSign = 1.0;
V3D detectorDir = q * qSign;
detectorDir[refFrame->pointingAlongBeam()] = one_over_wl - qBeam;
detectorDir.normalize();
......
......@@ -605,14 +605,21 @@ void PeaksWorkspace::saveNexus(::NeXus::File *file) const {
std::vector<double> goniometerMatrix(9 * np);
std::vector<std::string> shapes(np);
// HKL is flipped by -1 due to different q convention in Crystallography.
// Always write out in ki-kf so consistent with old files
double qSign = 1.0;
std::string convention = ConfigService::Instance().getString("Q.convention");
if (convention == "Crystallography")
qSign = -1.0;
// Populate column vectors from Peak Workspace
size_t maxShapeJSONLength = 0;
for (size_t i = 0; i < np; i++) {
Peak p = peaks[i];
detectorID[i] = p.getDetectorID();
H[i] = p.getH();
K[i] = p.getK();
L[i] = p.getL();
H[i] = qSign * p.getH();
K[i] = qSign * p.getK();
L[i] = qSign * p.getL();
intensity[i] = p.getIntensity();
sigmaIntensity[i] = p.getSigmaIntensity();
binCount[i] = p.getBinCount();
......
......@@ -58,6 +58,12 @@ public:
min = static_cast<T>(min * scaling + offset);
max = static_cast<T>(max * scaling + offset);
m_size = static_cast<T>(m_size * scaling);
if (max < min) {
T tmp = max;
max = min;
min = tmp;
m_size = std::fabs(m_size);
}
}
// it looks like this loses accuracy?
void expand(MDDimensionExtents &other) {
......
......@@ -673,10 +673,15 @@ void ConfigServiceImpl::createUserPropertiesFile() const {
filestr << "## e.g.: ISIS, SNS, ILL" << std::endl;
filestr << "default.facility=" << std::endl;
filestr << std::endl;
filestr << "## Stes the default instrument" << std::endl;
filestr << "## Sets the default instrument" << std::endl;
filestr << "## e.g. IRIS, HET, NIMROD" << std::endl;
filestr << "default.instrument=" << std::endl;
filestr << std::endl;
filestr << std::endl;
filestr << "## Sets the Q.convention" << std::endl;
filestr << "## Set to Crystallography for kf-ki instead of default "
"Inelastic which is ki-kf" << std::endl;
filestr << "#Q.convention=Crystallography" << std::endl;
filestr << "##" << std::endl;
filestr << "## DIRECTORIES" << std::endl;
filestr << "##" << std::endl;
......
......@@ -46,6 +46,9 @@ private:
void init();
void exec();
// ki-kf for Inelastic convention; kf-ki for Crystallography convention
std::string convention =
Kernel::ConfigService::Instance().getString("Q.convention");
/// limits for h,k,l,dE dimensions
coord_t m_hmin, m_hmax, m_kmin, m_kmax, m_lmin, m_lmax, m_dEmin, m_dEmax;
/// cached values for incident energy and momentum, final momentum min/max
......
......@@ -66,6 +66,10 @@ private:
/// Run the algorithm
void exec();
// ki-kf for Inelastic convention; kf-ki for Crystallography convention
std::string convention =
Kernel::ConfigService::Instance().getString("Q.convention");
/// Helper method
template <typename MDE, size_t nd>
void doLoad(typename DataObjects::MDEventWorkspace<MDE, nd>::sptr ws);
......@@ -84,6 +88,8 @@ private:
void loadCoordinateSystem();
void loadQConvention();
void loadVisualNormalization(
const std::string &key,
boost::optional<Mantid::API::MDNormalization> &normalization);
......@@ -114,6 +120,8 @@ private:
std::vector<Mantid::Geometry::IMDDimension_sptr> m_dims;
/// Coordinate system
Kernel::SpecialCoordinateSystem m_coordSystem;
/// QConvention
std::string m_QConvention;
/// load only the box structure with empty boxes but do not tload boxes events
bool m_BoxStructureAndMethadata;
......
......@@ -88,6 +88,9 @@ private:
Kernel::V3D m_samplePos;
/// Beam direction
Kernel::V3D m_beamDir;
/// ki-kf for Inelastic convention; kf-ki for Crystallography convention
std::string convention =
Kernel::ConfigService::Instance().getString("Q.convention");
};
} // namespace MDAlgorithms
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment