51void writeRow(std::shared_ptr<Mantid::DataObjects::TableWorkspace> &vertexes,
const V2D &vertex,
size_t nHisto,
52 size_t nBins,
double signal,
double error) {
53 TableRow row = vertexes->appendRow();
54 row << vertex.
X() << vertex.
Y() << int(nHisto) << int(nBins) << signal <<
error;
62 if (outputDimensions ==
"Q (lab frame)") {
67 vertexes.
addColumn(
"double",
"CellSignal");
68 vertexes.
addColumn(
"double",
"CellError");
70 if (outputDimensions ==
"P (lab frame)") {
75 vertexes.
addColumn(
"double",
"CellSignal");
76 vertexes.
addColumn(
"double",
"CellError");
78 if (outputDimensions ==
"K (incident, final)") {
83 vertexes.
addColumn(
"double",
"CellSignal");
84 vertexes.
addColumn(
"double",
"CellError");
105 std::string d1Label, std::string d1ID,
double d1Min,
double d1Max,
107 : m_d0NumBins(d0NumBins), m_d1NumBins(d1NumBins), m_d0Min(d0Min), m_d1Min(d1Min), m_d0Max(d0Max), m_d1Max(d1Max),
108 m_d0Label(
std::move(d0Label)), m_d1Label(
std::move(d1Label)), m_d0ID(
std::move(d0ID)), m_d1ID(
std::move(d1ID)),
110 if (d0Min >= d0Max || d1Min >= d1Max)
111 throw std::invalid_argument(
"The supplied minimum values must be less than the maximum values.");
120std::shared_ptr<MDEventWorkspace2Lean>
124 auto ws = std::make_shared<MDEventWorkspace2Lean>();
130 wsbc->setSplitInto(boxController->getSplitInto(0));
131 wsbc->setMaxDepth(boxController->getMaxDepth());
132 wsbc->setSplitThreshold(boxController->getSplitThreshold());
153 const std::string &caption,
const std::string &units) {
155 auto xAxis = std::make_unique<BinEdgeAxis>(nBins);
156 auto xAxisRaw = xAxis.get();
159 std::shared_ptr<Mantid::Kernel::Units::Label> xUnit =
160 std::dynamic_pointer_cast<Mantid::Kernel::Units::Label>(unitXBasePtr);
161 xUnit->setLabel(caption, units);
162 xAxisRaw->unit() = xUnit;
163 xAxisRaw->title() = caption;
165 for (
size_t i = 0; i < nBins; ++i) {
166 double qxIncrement = ((1 / gradX) * (
static_cast<double>(i) + 1) + cxToUnit);
167 xAxisRaw->setValue(i, qxIncrement);
168 xAxisVec[i] = qxIncrement;
184 const size_t nBins,
const std::string &caption,
const std::string &units) {
186 auto verticalAxis = std::make_unique<BinEdgeAxis>(nBins);
187 auto verticalAxisRaw = verticalAxis.get();
190 std::shared_ptr<Mantid::Kernel::Units::Label> verticalUnit =
191 std::dynamic_pointer_cast<Mantid::Kernel::Units::Label>(unitZBasePtr);
192 verticalAxisRaw->unit() = verticalUnit;
193 verticalUnit->setLabel(caption, units);
194 verticalAxisRaw->title() = caption;
195 auto xAxis = Kernel::make_cow<HistogramData::HistogramX>(xAxisVec);
196 for (
size_t i = 0; i < nBins; ++i) {
198 double qzIncrement = ((1 / gradY) * (
static_cast<double>(i) + 1) + cyToUnit);
199 verticalAxisRaw->setValue(i, qzIncrement);
212 const size_t nhist =
workspace->getNumberHistograms();
213 std::vector<double> twoThetas(nhist);
214 std::vector<double> twoThetaWidths(nhist);
215 std::vector<double> detectorHeights(nhist);
218 const V3D upDirVec = inst->getReferenceFrame()->vecPointingUp();
220 const auto &spectrumInfo =
workspace->spectrumInfo();
221 const auto &detectorInfo =
workspace->detectorInfo();
222 for (
size_t i = 0; i < nhist; ++i) {
223 if (!spectrumInfo.hasDetectors(i) || spectrumInfo.isMonitor(i)) {
226 twoThetaWidths[i] = -1.0;
243 size_t detIndex = detectorInfo.indexOf(spectrumInfo.detector(i).getID());
244 double l2 = detectorInfo.l2(detIndex);
246 auto shape = detectorInfo.detector(detIndex).shape();
250 auto span = maxPoint - minPoint;
251 detectorHeights[i] = span.scalar_prod(upDirVec);
253 (std::atan(maxPoint.scalar_prod(upDirVec) /
l2) - std::atan(minPoint.scalar_prod(upDirVec) /
l2)) *
rad2deg;
279 auto spectraAxis = inputWs->getAxis(1);
280 for (
size_t index = 0;
index < inputWs->getNumberHistograms(); ++
index) {
281 auto counts = inputWs->readY(
index);
282 auto wavelengths = inputWs->readX(
index);
283 auto errors = inputWs->readE(
index);
284 const size_t nInputBins = wavelengths.size() - 1;
288 for (
size_t binIndex = 0; binIndex < nInputBins; ++binIndex) {
289 const double &wavelength = 0.5 * (wavelengths[binIndex] + wavelengths[binIndex + 1]);
292 double centers[2] = {_d0, _d1};
294 ws->addEvent(
MDLeanEvent<2>(
float(counts[binIndex]),
float(errors[binIndex] * errors[binIndex]), centers));
297 ws->splitAllIfNeeded(
nullptr);
309 auto ws = std::make_shared<Mantid::DataObjects::Workspace2D>();
318 const double cxToIndex = -gradD0 *
m_d0Min;
319 const double cyToIndex = -gradD1 *
m_d1Min;
320 const double cxToD0 =
m_d0Min - (1 / gradD0);
321 const double cyToD1 =
m_d1Min - (1 / gradD1);
330 auto spectraAxis = inputWs->getAxis(1);
331 for (
size_t index = 0;
index < inputWs->getNumberHistograms(); ++
index) {
332 auto counts = inputWs->readY(
index);
333 auto wavelengths = inputWs->readX(
index);
334 auto errors = inputWs->readE(
index);
335 const size_t nInputBins = wavelengths.size() - 1;
339 for (
size_t binIndex = 0; binIndex < nInputBins; ++binIndex) {
340 const double wavelength = 0.5 * (wavelengths[binIndex] + wavelengths[binIndex + 1]);
347 const auto outIndexX =
static_cast<int>((gradD0 * _d0) + cxToIndex);
348 const auto outIndexZ =
static_cast<int>((gradD1 * _d1) + cyToIndex);
350 ws->dataY(outIndexZ)[outIndexX] += counts[binIndex];
351 ws->dataE(outIndexZ)[outIndexX] += errors[binIndex];
360 auto input_x_dim = inputWs->getXDimension();
363 new MDHistoDimension(input_x_dim->getName(), input_x_dim->getDimensionId(), input_x_dim->getMDFrame(),
365 static_cast<Mantid::coord_t>(input_x_dim->getMaximum()), input_x_dim->getNBins()));
367 auto input_y_dim = inputWs->getYDimension();
370 new MDHistoDimension(input_y_dim->getName(), input_y_dim->getDimensionId(), input_y_dim->getMDFrame(),
372 static_cast<Mantid::coord_t>(input_y_dim->getMaximum()), input_y_dim->getNBins()));
374 auto outWs = std::make_shared<MDHistoWorkspace>(dim0, dim1);
376 for (
size_t nHistoIndex = 0; nHistoIndex < inputWs->getNumberHistograms(); ++nHistoIndex) {
377 const auto &
Y = inputWs->y(nHistoIndex);
378 const auto &E = inputWs->e(nHistoIndex);
380 const size_t numBins =
Y.size();
381 for (
size_t nBinIndex = 0; nBinIndex < numBins; ++nBinIndex) {
382 const auto value_index = outWs->getLinearIndex(nBinIndex, nHistoIndex);
383 outWs->setSignalAt(value_index,
Y[nBinIndex]);
384 outWs->setErrorSquaredAt(value_index, E[nBinIndex] * E[nBinIndex]);
400 std::shared_ptr<Mantid::DataObjects::TableWorkspace> &vertexes,
401 bool dumpVertexes,
const std::string &outputDimensions)
const {
409 std::vector<double> xBinsVec;
410 std::vector<double> zBinsVec;
415 auto verticalAxis = std::make_unique<BinEdgeAxis>(zBinsVec);
416 auto verticalAxisRaw = verticalAxis.get();
417 outWS->replaceAxis(1, std::move(verticalAxis));
418 HistogramData::BinEdges binEdges(xBinsVec);
419 for (
size_t i = 0; i < zBinsVec.size() - 1; ++i)
420 outWS->setBinEdges(i, binEdges);
429 const size_t nHistos = inputWS->getNumberHistograms();
430 const size_t nBins = inputWS->blocksize();
433 std::vector<specnum_t> specNumberMapping;
434 std::vector<detid_t> detIDMapping;
436 addColumnHeadings(*vertexes, outputDimensions);
437 const auto &spectrumInfo = inputWS->spectrumInfo();
438 for (
size_t i = 0; i < nHistos; ++i) {
439 if (!spectrumInfo.hasDetectors(i) || spectrumInfo.isMasked(i) || spectrumInfo.isMonitor(i)) {
442 const auto &detector = spectrumInfo.detector(i);
445 const double twoTheta = twoThetas[i];
446 const double twoThetaWidth = twoThetaWidths[i];
447 const double twoThetaHalfWidth = 0.5 * twoThetaWidth;
448 const double twoThetaLower =
twoTheta - twoThetaHalfWidth;
449 const double twoThetaUpper =
twoTheta + twoThetaHalfWidth;
454 for (
size_t j = 0; j < nBins; ++j) {
455 const double lamLower =
X[j];
456 const double lamUpper =
X[j + 1];
457 const double signal =
Y[j];
458 const double error = E[j];
460 auto inputQ =
m_calculator->createQuad(lamUpper, lamLower, twoThetaUpper, twoThetaLower);
463 const auto qIndex = std::upper_bound(zBinsVec.begin(), zBinsVec.end(), inputQ[0].Y()) - zBinsVec.begin();
464 if (qIndex != 0 && qIndex <
static_cast<int>(zBinsVec.size())) {
466 specNumberMapping.emplace_back(outWS->getSpectrum(qIndex - 1).getSpectrumNo());
467 detIDMapping.emplace_back(detector.getID());
471 writeRow(vertexes, inputQ[0], i, j, signal,
error);
472 writeRow(vertexes, inputQ[1], i, j, signal,
error);
473 writeRow(vertexes, inputQ[2], i, j, signal,
error);
474 writeRow(vertexes, inputQ[3], i, j, signal,
error);
483 outWS->updateSpectraUsing(outputDetectorMap);
486 outWS->setYUnitLabel(
"Intensity");
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
Base MatrixWorkspace Abstract Class.
void replaceAxis(const std::size_t &axisIndex, std::unique_ptr< Axis > newAxis)
Replaces one of the workspace's axes with the new one provided.
virtual void setX(const std::size_t index, const Kernel::cow_ptr< HistogramData::HistogramX > &X)
Deprecated, use setSharedX() instead.
A minimal class to hold the mapping between the spectrum number and its related detector ID numbers f...
TableRow represents a row in a TableWorkspace.
Provides a common interface to Reflectometry Transform calculators.
Templated class holding data about a neutron detection event in N-dimensions (for example,...
TableWorkspace is an implementation of Workspace in which the data are organised in columns of same s...
API::Column_sptr addColumn(const std::string &type, const std::string &name) override
Creates a new column.
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
const Kernel::V3D & minPoint() const
Returns the min point of the box.
const Kernel::V3D & maxPoint() const
Returns the min point of the box.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Implements a 2-dimensional vector embedded in a 3D space, i.e.
double Y() const
Y position.
double X() const
X position.
std::shared_ptr< IMDEventWorkspace > IMDEventWorkspace_sptr
Shared pointer to Mantid::API::IMDEventWorkspace.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< IMDHistoWorkspace > IMDHistoWorkspace_sptr
shared pointer to Mantid::API::IMDHistoWorkspace
std::shared_ptr< BoxController > BoxController_sptr
Shared ptr to BoxController.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
MANTID_DATAOBJECTS_DLL void normaliseOutput(const API::MatrixWorkspace_sptr &outputWS, const API::MatrixWorkspace_const_sptr &inputWS, API::Progress *progress=nullptr)
Compute sqrt of errors and put back in bin width division if necessary.
MANTID_DATAOBJECTS_DLL void rebinToFractionalOutput(const Geometry::Quadrilateral &inputQ, const API::MatrixWorkspace_const_sptr &inputWS, const size_t i, const size_t j, DataObjects::RebinnedOutput &outputWS, const std::vector< double > &verticalAxis, const DataObjects::RebinnedOutput_const_sptr &inputRB=nullptr)
Rebin the input quadrilateral to to output grid.
MANTID_DATAOBJECTS_DLL void finalizeFractionalRebin(DataObjects::RebinnedOutput &outputWS)
Set finalize flag after fractional rebinning loop.
MANTID_DATAOBJECTS_DLL void createVerticalAxis(Mantid::API::MatrixWorkspace *const ws, const MantidVec &xAxisVec, const double gradY, const double cyToUnit, const size_t nBins, const std::string &caption, const std::string &units)
Create a new y(vertical)-axis for the output workspace.
MANTID_DATAOBJECTS_DLL DetectorAngularCache initAngularCaches(const Mantid::API::MatrixWorkspace *const workspace)
Create angular caches.
MANTID_DATAOBJECTS_DLL MantidVec createXAxis(Mantid::API::MatrixWorkspace *const ws, const double gradX, const double cxToUnit, const size_t nBins, const std::string &caption, const std::string &units)
Create a new x-axis for the output workspace.
std::shared_ptr< RebinnedOutput > RebinnedOutput_sptr
shared pointer to the RebinnedOutput class
std::unique_ptr< MDFrame > MDFrame_uptr
constexpr double rad2deg
Radians to degrees conversion factor.
std::shared_ptr< IMDDimension > IMDDimension_sptr
Shared Pointer for IMDDimension. Frequently used type in framework.
std::shared_ptr< MDHistoDimension > MDHistoDimension_sptr
Shared pointer to a MDHistoDimension.
int MANTID_KERNEL_DLL createAxisFromRebinParams(const std::vector< double > ¶ms, std::vector< double > &xnew, const bool resize_xnew=true, const bool full_bins_only=false, const double xMinHint=std::nan(""), const double xMaxHint=std::nan(""), const bool useReverseLogarithmic=false, const double power=-1)
Creates a new output X array given a 'standard' set of rebinning parameters.
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Simple container for porting detector angular information.
std::vector< double > detectorHeights
std::vector< double > twoThetas
std::vector< double > twoThetaWidths