52void writeRow(std::shared_ptr<Mantid::DataObjects::TableWorkspace> &vertexes,
const V2D &vertex,
size_t nHisto,
53 size_t nBins,
double signal,
double error) {
54 TableRow row = vertexes->appendRow();
55 row << vertex.
X() << vertex.
Y() << int(nHisto) << int(nBins) << signal <<
error;
63 if (outputDimensions ==
"Q (lab frame)") {
68 vertexes.
addColumn(
"double",
"CellSignal");
69 vertexes.
addColumn(
"double",
"CellError");
71 if (outputDimensions ==
"P (lab frame)") {
76 vertexes.
addColumn(
"double",
"CellSignal");
77 vertexes.
addColumn(
"double",
"CellError");
79 if (outputDimensions ==
"K (incident, final)") {
84 vertexes.
addColumn(
"double",
"CellSignal");
85 vertexes.
addColumn(
"double",
"CellError");
106 std::string d1Label, std::string d1ID,
double d1Min,
double d1Max,
108 : m_d0NumBins(d0NumBins), m_d1NumBins(d1NumBins), m_d0Min(d0Min), m_d1Min(d1Min), m_d0Max(d0Max), m_d1Max(d1Max),
109 m_d0Label(
std::move(d0Label)), m_d1Label(
std::move(d1Label)), m_d0ID(
std::move(d0ID)), m_d1ID(
std::move(d1ID)),
111 if (d0Min >= d0Max || d1Min >= d1Max)
112 throw std::invalid_argument(
"The supplied minimum values must be less than the maximum values.");
121std::shared_ptr<MDEventWorkspace2Lean>
125 auto ws = std::make_shared<MDEventWorkspace2Lean>();
131 wsbc->setSplitInto(boxController->getSplitInto(0));
132 wsbc->setMaxDepth(boxController->getMaxDepth());
133 wsbc->setSplitThreshold(boxController->getSplitThreshold());
154 const std::string &caption,
const std::string &units) {
156 auto xAxis = std::make_unique<BinEdgeAxis>(nBins);
157 auto xAxisRaw = xAxis.get();
159 auto unitXBasePtr = UnitFactory::Instance().create(
"Label");
160 std::shared_ptr<Mantid::Kernel::Units::Label> xUnit =
161 std::dynamic_pointer_cast<Mantid::Kernel::Units::Label>(unitXBasePtr);
162 xUnit->setLabel(caption, units);
163 xAxisRaw->unit() = xUnit;
164 xAxisRaw->title() = caption;
166 for (
size_t i = 0; i < nBins; ++i) {
167 double qxIncrement = ((1 / gradX) * (
static_cast<double>(i) + 1) + cxToUnit);
168 xAxisRaw->setValue(i, qxIncrement);
169 xAxisVec[i] = qxIncrement;
185 const size_t nBins,
const std::string &caption,
const std::string &units) {
187 auto verticalAxis = std::make_unique<BinEdgeAxis>(nBins);
188 auto verticalAxisRaw = verticalAxis.get();
190 auto unitZBasePtr = UnitFactory::Instance().create(
"Label");
191 std::shared_ptr<Mantid::Kernel::Units::Label> verticalUnit =
192 std::dynamic_pointer_cast<Mantid::Kernel::Units::Label>(unitZBasePtr);
193 verticalAxisRaw->unit() = verticalUnit;
194 verticalUnit->setLabel(caption, units);
195 verticalAxisRaw->title() = caption;
196 auto xAxis = Kernel::make_cow<HistogramData::HistogramX>(xAxisVec);
197 for (
size_t i = 0; i < nBins; ++i) {
199 double qzIncrement = ((1 / gradY) * (
static_cast<double>(i) + 1) + cyToUnit);
200 verticalAxisRaw->setValue(i, qzIncrement);
213 const size_t nhist =
workspace->getNumberHistograms();
214 std::vector<double> twoThetas(nhist);
215 std::vector<double> twoThetaWidths(nhist);
216 std::vector<double> detectorHeights(nhist);
219 const V3D upDirVec = inst->getReferenceFrame()->vecPointingUp();
221 const auto &spectrumInfo =
workspace->spectrumInfo();
222 const auto &detectorInfo =
workspace->detectorInfo();
223 const auto &componentInfo =
workspace->componentInfo();
224 for (
size_t i = 0; i < nhist; ++i) {
225 if (!spectrumInfo.hasDetectors(i) || spectrumInfo.isMonitor(i)) {
228 twoThetaWidths[i] = -1.0;
245 size_t detIndex = spectrumInfo.firstDetectorIndex(i);
246 double l2 = detectorInfo.l2(detIndex);
249 BoundingBox bbox = componentInfo.shape(detIndex).getBoundingBox();
252 auto span = maxPoint - minPoint;
253 detectorHeights[i] = span.scalar_prod(upDirVec);
255 (std::atan(maxPoint.scalar_prod(upDirVec) /
l2) - std::atan(minPoint.scalar_prod(upDirVec) /
l2)) *
rad2deg;
281 auto spectraAxis = inputWs->getAxis(1);
282 for (
size_t index = 0;
index < inputWs->getNumberHistograms(); ++
index) {
283 auto counts = inputWs->y(
index);
284 auto wavelengths = inputWs->x(
index);
285 auto errors = inputWs->e(
index);
286 const size_t nInputBins = wavelengths.size() - 1;
290 for (
size_t binIndex = 0; binIndex < nInputBins; ++binIndex) {
291 const double &wavelength = 0.5 * (wavelengths[binIndex] + wavelengths[binIndex + 1]);
294 double centers[2] = {_d0, _d1};
296 ws->addEvent(
MDLeanEvent<2>(
float(counts[binIndex]),
float(errors[binIndex] * errors[binIndex]), centers));
299 ws->splitAllIfNeeded(
nullptr);
311 auto ws = std::make_shared<Mantid::DataObjects::Workspace2D>();
320 const double cxToIndex = -gradD0 *
m_d0Min;
321 const double cyToIndex = -gradD1 *
m_d1Min;
322 const double cxToD0 =
m_d0Min - (1 / gradD0);
323 const double cyToD1 =
m_d1Min - (1 / gradD1);
332 auto spectraAxis = inputWs->getAxis(1);
333 for (
size_t index = 0;
index < inputWs->getNumberHistograms(); ++
index) {
334 auto counts = inputWs->y(
index);
335 auto wavelengths = inputWs->x(
index);
336 auto errors = inputWs->e(
index);
337 const size_t nInputBins = wavelengths.size() - 1;
341 for (
size_t binIndex = 0; binIndex < nInputBins; ++binIndex) {
342 const double wavelength = 0.5 * (wavelengths[binIndex] + wavelengths[binIndex + 1]);
349 const auto outIndexX =
static_cast<int>((gradD0 * _d0) + cxToIndex);
350 const auto outIndexZ =
static_cast<int>((gradD1 * _d1) + cyToIndex);
352 ws->mutableY(outIndexZ)[outIndexX] += counts[binIndex];
353 ws->mutableE(outIndexZ)[outIndexX] += errors[binIndex];
362 auto input_x_dim = inputWs->getXDimension();
365 new MDHistoDimension(input_x_dim->getName(), input_x_dim->getDimensionId(), input_x_dim->getMDFrame(),
367 static_cast<Mantid::coord_t>(input_x_dim->getMaximum()), input_x_dim->getNBins()));
369 auto input_y_dim = inputWs->getYDimension();
372 new MDHistoDimension(input_y_dim->getName(), input_y_dim->getDimensionId(), input_y_dim->getMDFrame(),
374 static_cast<Mantid::coord_t>(input_y_dim->getMaximum()), input_y_dim->getNBins()));
376 auto outWs = std::make_shared<MDHistoWorkspace>(dim0, dim1);
378 for (
size_t nHistoIndex = 0; nHistoIndex < inputWs->getNumberHistograms(); ++nHistoIndex) {
379 const auto &
Y = inputWs->y(nHistoIndex);
380 const auto &E = inputWs->e(nHistoIndex);
382 const size_t numBins =
Y.size();
383 for (
size_t nBinIndex = 0; nBinIndex < numBins; ++nBinIndex) {
384 const auto value_index = outWs->getLinearIndex(nBinIndex, nHistoIndex);
385 outWs->setSignalAt(value_index,
Y[nBinIndex]);
386 outWs->setErrorSquaredAt(value_index, E[nBinIndex] * E[nBinIndex]);
402 std::shared_ptr<Mantid::DataObjects::TableWorkspace> &vertexes,
403 bool dumpVertexes,
const std::string &outputDimensions)
const {
411 std::vector<double> xBinsVec;
412 std::vector<double> zBinsVec;
417 auto verticalAxis = std::make_unique<BinEdgeAxis>(zBinsVec);
418 auto verticalAxisRaw = verticalAxis.get();
419 outWS->replaceAxis(1, std::move(verticalAxis));
420 HistogramData::BinEdges binEdges(xBinsVec);
421 for (
size_t i = 0; i < zBinsVec.size() - 1; ++i)
422 outWS->setBinEdges(i, binEdges);
431 const size_t nHistos = inputWS->getNumberHistograms();
432 const size_t nBins = inputWS->blocksize();
435 std::vector<specnum_t> specNumberMapping;
436 std::vector<detid_t> detIDMapping;
438 addColumnHeadings(*vertexes, outputDimensions);
439 const auto &spectrumInfo = inputWS->spectrumInfo();
440 for (
size_t i = 0; i < nHistos; ++i) {
441 if (!spectrumInfo.hasDetectors(i) || spectrumInfo.isMasked(i) || spectrumInfo.isMonitor(i)) {
445 const auto detID = spectrumInfo.firstDetectorID(i);
448 const double twoTheta = twoThetas[i];
449 const double twoThetaWidth = twoThetaWidths[i];
450 const double twoThetaHalfWidth = 0.5 * twoThetaWidth;
451 const double twoThetaLower =
twoTheta - twoThetaHalfWidth;
452 const double twoThetaUpper =
twoTheta + twoThetaHalfWidth;
454 Mantid::HistogramData::HistogramX
const &
X = inputWS->x(i);
455 Mantid::HistogramData::HistogramY
const &
Y = inputWS->y(i);
456 Mantid::HistogramData::HistogramE
const &E = inputWS->e(i);
457 for (
size_t j = 0; j < nBins; ++j) {
458 const double lamLower =
X[j];
459 const double lamUpper =
X[j + 1];
460 const double signal =
Y[j];
461 const double error = E[j];
463 auto inputQ =
m_calculator->createQuad(lamUpper, lamLower, twoThetaUpper, twoThetaLower);
466 const auto qIndex = std::upper_bound(zBinsVec.begin(), zBinsVec.end(), inputQ[0].Y()) - zBinsVec.begin();
467 if (qIndex != 0 && qIndex <
static_cast<int>(zBinsVec.size())) {
469 specNumberMapping.emplace_back(outWS->getSpectrum(qIndex - 1).getSpectrumNo());
470 detIDMapping.emplace_back(detID);
474 writeRow(vertexes, inputQ[0], i, j, signal,
error);
475 writeRow(vertexes, inputQ[1], i, j, signal,
error);
476 writeRow(vertexes, inputQ[2], i, j, signal,
error);
477 writeRow(vertexes, inputQ[3], i, j, signal,
error);
486 outWS->updateSpectraUsing(outputDetectorMap);
489 outWS->setYUnitLabel(
"Intensity");
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
Base MatrixWorkspace Abstract Class.
void setSharedX(const size_t index, const Kernel::cow_ptr< HistogramData::HistogramX > &x) &
void replaceAxis(const std::size_t &axisIndex, std::unique_ptr< Axis > newAxis)
Replaces one of the workspace's axes with the new one provided.
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, std::span< double const > 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.
std::size_t 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