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 "MantidKernel/System.h"
13#include <limits>
14
15using namespace Mantid::Kernel;
16using namespace Mantid::API;
17using namespace Mantid::DataObjects;
18
19namespace Mantid::Algorithms {
20
21// Register the algorithm into the AlgorithmFactory
22DECLARE_ALGORITHM(ConvertToEventWorkspace)
23
24
27 declareProperty(std::make_unique<WorkspaceProperty<Workspace2D>>("InputWorkspace", "", Direction::Input),
28 "An input Workspace2D.");
29 declareProperty("GenerateZeros", false,
30 "Generate an event even for empty bins\n"
31 "Warning! This may use significantly more memory.");
32 declareProperty("GenerateMultipleEvents", false,
33 "Generate a number of evenly spread events in each bin. See "
34 "the help for details.\n"
35 "Warning! This may use significantly more memory.");
36 declareProperty("MaxEventsPerBin", 10,
37 "If GenerateMultipleEvents is true, specifies a maximum number of events "
38 "to generate in a single bin.\n"
39 "Use a value that matches your instrument's TOF resolution. Default 10.");
40 declareProperty(std::make_unique<WorkspaceProperty<EventWorkspace>>("OutputWorkspace", "", Direction::Output),
41 "Name of the output EventWorkspace.");
42}
43
47 Workspace2D_const_sptr inWS = getProperty("InputWorkspace");
48
49 bool GenerateMultipleEvents = getProperty("GenerateMultipleEvents");
50 bool GenerateZeros = getProperty("GenerateZeros");
51 int MaxEventsPerBin = getProperty("MaxEventsPerBin");
52
53 auto outWS = create<EventWorkspace>(*inWS);
54
55 Progress prog(this, 0.0, 1.0, inWS->getNumberHistograms());
57 for (int iwi = 0; iwi < int(inWS->getNumberHistograms()); iwi++) {
59 auto wi = size_t(iwi);
60
61 // The input spectrum (a histogram)
62 const auto &inSpec = inWS->getSpectrum(wi);
63
64 // The output event list
65 EventList &el = outWS->getSpectrum(wi);
66
67 // This method fills in the events
68 el.createFromHistogram(&inSpec, GenerateZeros, GenerateMultipleEvents, MaxEventsPerBin);
69
70 prog.report("Converting");
72 }
74
75 // Set the output
76 setProperty("OutputWorkspace", std::move(outWS));
77}
78
79} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
#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...
Definition: MultiThreaded.h:94
#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.
Definition: Algorithm.cpp:2076
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:56
void createFromHistogram(const ISpectrum *inSpec, bool GenerateZeros, bool GenerateMultipleEvents, int MaxEventsPerBin)
Create an EventList from a histogram.
Definition: EventList.cpp:229
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.
Definition: ProgressBase.h:51
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.
Definition: MultiThreaded.h:22
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54