Mantid
Loading...
Searching...
No Matches
EventWorkspaceHelpers.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 +
12
13using namespace Mantid::API;
14using namespace Mantid::DataObjects;
15
16namespace Mantid::DataObjects {
17
23 EventWorkspace_sptr inputW = std::dynamic_pointer_cast<EventWorkspace>(inputMatrixW);
24 if (!inputW)
25 throw std::invalid_argument("EventWorkspaceHelpers::convertEventTo2D(): "
26 "Input workspace is not an EventWorkspace.");
27
28 size_t numBins = inputW->blocksize();
29
30 // Make a workspace 2D version of it
32 outputW = WorkspaceFactory::Instance().create("Workspace2D", inputW->getNumberHistograms(), numBins + 1, numBins);
33 WorkspaceFactory::Instance().initializeFromParent(*inputW, *outputW, false);
34
35 // Now let's set all the X bins and values
36 for (size_t i = 0; i < inputW->getNumberHistograms(); i++) {
37 outputW->getSpectrum(i).copyInfoFrom(inputW->getSpectrum(i));
38 outputW->setX(i, inputW->refX(i));
39
40 MantidVec &Yout = outputW->dataY(i);
41 const MantidVec &Yin = inputW->readY(i);
42 for (size_t j = 0; j < numBins; j++)
43 Yout[j] = Yin[j];
44
45 MantidVec &Eout = outputW->dataE(i);
46 const MantidVec &Ein = inputW->readE(i);
47 for (size_t j = 0; j < numBins; j++)
48 Eout[j] = Ein[j];
49 }
50
51 return outputW;
52}
53
54} // namespace Mantid::DataObjects
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Definition: cow_ptr.h:172
static API::MatrixWorkspace_sptr convertEventTo2D(const API::MatrixWorkspace_sptr &inputMatrixW)
Converts an EventWorkspace to an equivalent Workspace2D.