25using Mantid::Types::Event::TofEvent;
49 "An input MatrixWorkspace.");
51 "A list of the bank numbers to convert. If empty, will use "
52 "all banksMust have at least one entry.");
58 "Name of the output MDEventWorkspace.");
75template <
class T,
class MDE,
size_t nd>
78 uint16_t expInfoIndex, uint16_t goniometerIndex, int32_t detectorID) {
83 std::vector<MDE> out_events;
88 typename std::vector<T> *events_ptr;
90 typename std::vector<T> &events = *events_ptr;
93 auto it = events.begin();
94 auto it_end = events.end();
96 for (; it != it_end; it++) {
97 auto tof =
static_cast<coord_t>(it->tof());
100 out_events.emplace_back(
float(it->weight()), float(it->errorSquared()), expInfoIndex, goniometerIndex, detectorID,
102 }
else if (nd == 4) {
103 coord_t center[4] = {
x,
y, tof, bankNum};
104 out_events.emplace_back(
static_cast<float>(it->weight()),
static_cast<float>(it->errorSquared()), expInfoIndex,
105 detectorID, goniometerIndex, center);
110 outWS->addEvents(out_events);
122 std::vector<int> bankNums = this->
getProperty(
"BankNumbers");
123 std::sort(bankNums.begin(), bankNums.end());
125 std::map<int, RectangularDetector_const_sptr> banks;
127 if (bankNums.empty()) {
130 std::vector<IComponent_const_sptr> comps;
131 inst->getChildren(comps,
true);
133 for (
auto &comp : comps) {
137 std::string
name = det->getName();
140 std::string bank =
name.substr(4,
name.size() - 4);
143 banks[bankNum] = det;
144 g_log.
debug() <<
"Found bank " << bank <<
".\n";
149 for (
auto &bankNum : bankNums) {
154 banks[bankNum] = det;
158 for (
auto &bank : banks) {
168 throw std::runtime_error(
"No RectangularDetectors with a name like "
169 "'bankXX' found in the instrument.");
181 in_ws = std::dynamic_pointer_cast<EventWorkspace>(mws);
183 throw std::runtime_error(
"InputWorkspace is not an EventWorkspace");
189 std::map<int, RectangularDetector_const_sptr> banks = this->
getBanks();
192 double tof_min, tof_max;
194 in_ws->getXMinMax(tof_min, tof_max);
209 std::string TOFname = ax0->
title();
211 TOFname = ax0->
unit()->unitID();
215 std::vector<IMDDimension_sptr> dims{dimX, dimY, dimTOF};
217 if (banks.size() > 1) {
219 int min = banks.begin()->first;
220 int max = banks.rbegin()->first + 1;
222 static_cast<coord_t>(max), max - min));
223 dims.emplace_back(dimBanks);
228 size_t nd = dims.size();
230 outWS->initGeometry(dims);
240 uint16_t expInfoIndex = outWS->addExperimentInfo(ei);
241 uint16_t goniometerIndex(0);
243 for (
auto &bank : banks) {
244 int bankNum = bank.first;
246 for (
int x = 0;
x < det->xpixels();
x++)
247 for (
int y = 0;
y < det->ypixels();
y++) {
249 detid_t detID = det->getDetectorIDAtXY(
x,
y);
251 if (wi >=
in_ws->getNumberHistograms())
252 throw std::runtime_error(
"Invalid workspace index found in bank " + det->getName() +
"!");
254 auto xPos =
static_cast<coord_t>(
x);
255 auto yPos =
static_cast<coord_t>(
y);
256 auto bankPos =
static_cast<coord_t>(bankNum);
262 boost::function<void()> func;
266 this->convertEventList<TofEvent, MDEvent<3>, 3>(outWS3, wi, xPos, yPos, bankPos, expInfoIndex,
267 goniometerIndex, detID);
269 this->convertEventList<TofEvent, MDEvent<4>, 4>(outWS4, wi, xPos, yPos, bankPos, expInfoIndex,
270 goniometerIndex, detID);
274 this->convertEventList<WeightedEvent, MDEvent<3>, 3>(outWS3, wi, xPos, yPos, bankPos, expInfoIndex,
275 goniometerIndex, detID);
277 this->convertEventList<WeightedEvent, MDEvent<4>, 4>(outWS4, wi, xPos, yPos, bankPos, expInfoIndex,
278 goniometerIndex, detID);
282 this->convertEventList<WeightedEventNoTime, MDEvent<3>, 3>(outWS3, wi, xPos, yPos, bankPos, expInfoIndex,
283 goniometerIndex, detID);
285 this->convertEventList<WeightedEventNoTime, MDEvent<4>, 4>(outWS4, wi, xPos, yPos, bankPos, expInfoIndex,
286 goniometerIndex, detID);
289 throw std::runtime_error(
"EventList had an unexpected data type!");
297 outWS->splitAllIfNeeded(ts);
299 outWS->refreshCache();
#define DECLARE_ALGORITHM(classname)
static std::unique_ptr< QThreadPool > tp
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Class to represent the axis of a workspace.
const std::string & title() const
Returns the user-defined title for this axis.
virtual std::size_t length() const =0
Get the length of the axis.
const std::shared_ptr< Kernel::Unit > & unit() const
The unit for this axis.
double getValue(const std::size_t &index, const std::size_t &verticalIndex=0) const
Gets the value at the specified index.
void setBoxController(const Mantid::API::BoxController_sptr &bc, const Mantid::Geometry::Instrument_const_sptr &instrument)
Set the settings in the given box controller.
void initBoxControllerProps(const std::string &SplitInto="5", int SplitThreshold=1000, int MaxRecursionDepth=5)
Initialise the properties.
A property class for workspaces.
std::size_t getNumberEvents() const override
Return the number of events in the list.
Mantid::API::EventType getEventType() const override
Return the type of Event vector contained within.
static API::IMDEventWorkspace_sptr CreateMDWorkspace(size_t nd, const std::string &eventType="MDLeanEvent", const Mantid::API::MDNormalization &preferredNormalization=Mantid::API::MDNormalization::VolumeNormalization, const Mantid::API::MDNormalization &preferredNormalizationHisto=Mantid::API::MDNormalization::VolumeNormalization)
Create a MDEventWorkspace of the given type.
Templated class for the multi-dimensional event workspace.
std::shared_ptr< MDEventWorkspace< MDE, nd > > sptr
Typedef for a shared pointer of this kind of event workspace.
GeneralFrame : Any MDFrame that isn't related to momemtum transfer.
static const std::string GeneralFrameName
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
A Thread Pool implementation that keeps a certain number of threads running (normally,...
A Largest Cost Thread Scheduler.
The ThreadScheduler object defines how tasks are allocated to threads and in what order.
Convert a MatrixWorkspace containing to a MD workspace for viewing the detector face.
detid_t m_detID_to_WI_offset
Mantid::DataObjects::EventWorkspace_sptr in_ws
The input event workspace.
const std::string name() const override
Algorithm's name for identification.
int m_numYPixels
Height in pixels of the widest detector.
void convertEventList(std::shared_ptr< Mantid::DataObjects::MDEventWorkspace< MDE, nd > > outWS, size_t workspaceIndex, coord_t x, coord_t y, coord_t bankNum, uint16_t expInfoIndex, uint16_t goniometerIndex, int32_t detectorID)
Convert an event list to 3/4D detector face space add it to the MDEventWorkspace.
int m_numXPixels
Width in pixels of the widest detector.
void init() override
Initialize the algorithm's properties.
std::map< int, Geometry::RectangularDetector_const_sptr > getBanks()
Get the list of banks, given the settings.
const std::string category() const override
Algorithm's category for identification.
std::vector< size_t > m_detID_to_WI
void exec() override
Execute the algorithm.
int version() const override
Algorithm's version for identification.
std::shared_ptr< IMDEventWorkspace > IMDEventWorkspace_sptr
Shared pointer to Mantid::API::IMDEventWorkspace.
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
DLLExport void getEventsFrom(EventList &el, std::vector< Types::Event::TofEvent > *&events)
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
std::shared_ptr< const RectangularDetector > RectangularDetector_const_sptr
std::shared_ptr< MDHistoDimension > MDHistoDimension_sptr
Shared pointer to a MDHistoDimension.
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
int convert(const std::string &A, T &out)
Convert a string into a number.
std::string toString(const T &value)
Convert a number to a string.
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
int32_t detid_t
Typedef for a detector ID.
@ Input
An input workspace.
@ Output
An output workspace.