Mantid
Loading...
Searching...
No Matches
ConvertToEventWorkspace.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#include <limits>
13
14using namespace Mantid::Kernel;
15using namespace Mantid::API;
16using namespace Mantid::DataObjects;
17
18namespace Mantid::Algorithms {
19
20// Register the algorithm into the AlgorithmFactory
21DECLARE_ALGORITHM(ConvertToEventWorkspace)
22
23
26 declareProperty(std::make_unique<WorkspaceProperty<Workspace2D>>("InputWorkspace", "", Direction::Input),
27 "An input Workspace2D.");
28 declareProperty("GenerateZeros", false,
29 "Generate an event even for empty bins\n"
30 "Warning! This may use significantly more memory.");
31 declareProperty("GenerateMultipleEvents", false,
32 "Generate a number of evenly spread events in each bin. See "
33 "the help for details.\n"
34 "Warning! This may use significantly more memory.");
35 declareProperty("MaxEventsPerBin", 10,
36 "If GenerateMultipleEvents is true, specifies a maximum number of events "
37 "to generate in a single bin.\n"
38 "Use a value that matches your instrument's TOF resolution. Default 10.");
39 declareProperty(std::make_unique<WorkspaceProperty<EventWorkspace>>("OutputWorkspace", "", Direction::Output),
40 "Name of the output EventWorkspace.");
41}
42
46 Workspace2D_const_sptr inWS = getProperty("InputWorkspace");
47
48 bool GenerateMultipleEvents = getProperty("GenerateMultipleEvents");
49 bool GenerateZeros = getProperty("GenerateZeros");
50 int MaxEventsPerBin = getProperty("MaxEventsPerBin");
51
52 auto outWS = create<EventWorkspace>(*inWS);
53
54 Progress prog(this, 0.0, 1.0, inWS->getNumberHistograms());
56 for (int iwi = 0; iwi < int(inWS->getNumberHistograms()); iwi++) {
58 auto wi = size_t(iwi);
59
60 // The input spectrum (a histogram)
61 const auto &inSpec = inWS->getSpectrum(wi);
62
63 // The output event list
64 EventList &el = outWS->getSpectrum(wi);
65
66 // This method fills in the events
67 el.createFromHistogram(&inSpec, GenerateZeros, GenerateMultipleEvents, MaxEventsPerBin);
68
69 prog.report("Converting");
71 }
73
74 // Set the output
75 setProperty("OutputWorkspace", std::move(outWS));
76}
77
78} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:538
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Helper class for reporting progress from algorithms.
Definition Progress.h:25
A property class for workspaces.
Perform a conversion for a Workspace2D to an equivalent EventWorkspace.
A class for holding :
Definition EventList.h:57
void createFromHistogram(const ISpectrum *inSpec, bool GenerateZeros, bool GenerateMultipleEvents, int MaxEventsPerBin)
Create an EventList from a histogram.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
std::shared_ptr< const Workspace2D > Workspace2D_const_sptr
shared pointer to Mantid::DataObjects::Workspace2D (const version)
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
@ Input
An input workspace.
Definition Property.h:53
@ Output
An output workspace.
Definition Property.h:54