Newer
Older
Janik Zikovsky
committed
#include "MantidAlgorithms/ConvertToEventWorkspace.h"
Federico Montesino Pouzols
committed
#include "MantidAPI/WorkspaceFactory.h"
Janik Zikovsky
committed
#include "MantidKernel/System.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/Events.h"
Janik Zikovsky
committed
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
namespace Mantid {
namespace Algorithms {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(ConvertToEventWorkspace)
//----------------------------------------------------------------------------------------------
/** Constructor
*/
ConvertToEventWorkspace::ConvertToEventWorkspace() {}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
ConvertToEventWorkspace::~ConvertToEventWorkspace() {}
//------------------------------------------MaxEventsPerBin----------------------------------------------------
//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void ConvertToEventWorkspace::init() {
declareProperty(new WorkspaceProperty<Workspace2D>("InputWorkspace", "",
Direction::Input),
"An input Workspace2D.");
declareProperty("GenerateZeros", false,
"Generate an event even for empty bins\n"
"Warning! This may use significantly more memory.");
declareProperty("GenerateMultipleEvents", false,
"Generate a number of evenly spread events in each bin. See "
"the help for details.\n"
"Warning! This may use significantly more memory.");
declareProperty(
"MaxEventsPerBin", 10,
"If GenerateMultipleEvents is true, specifies a maximum number of events "
"to generate in a single bin.\n"
"Use a value that matches your instrument's TOF resolution. Default 10.");
declareProperty(new WorkspaceProperty<EventWorkspace>("OutputWorkspace", "",
Direction::Output),
"Name of the output EventWorkspace.");
}
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void ConvertToEventWorkspace::exec() {
Workspace2D_const_sptr inWS = getProperty("InputWorkspace");
bool GenerateMultipleEvents = getProperty("GenerateMultipleEvents");
bool GenerateZeros = getProperty("GenerateZeros");
int MaxEventsPerBin = getProperty("MaxEventsPerBin");
// Create the event workspace
EventWorkspace_sptr outWS = boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create(
"EventWorkspace", inWS->getNumberHistograms(), inWS->blocksize() + 1,
inWS->blocksize()));
// Copy geometry, etc. over.
API::WorkspaceFactory::Instance().initializeFromParent(inWS, outWS, false);
Progress prog(this, 0.0, 1.0, inWS->getNumberHistograms());
PARALLEL_FOR1(inWS)
for (int iwi = 0; iwi < int(inWS->getNumberHistograms()); iwi++) {
PARALLEL_START_INTERUPT_REGION
size_t wi = size_t(iwi);
// The input spectrum (a histogram)
const ISpectrum *inSpec = inWS->getSpectrum(wi);
// The output event list
EventList &el = outWS->getEventList(wi);
// This method fills in the events
el.createFromHistogram(inSpec, GenerateZeros, GenerateMultipleEvents,
MaxEventsPerBin);
prog.report("Converting");
PARALLEL_END_INTERUPT_REGION
Janik Zikovsky
committed
}
Janik Zikovsky
committed
// Set the output
setProperty("OutputWorkspace", outWS);
}
Janik Zikovsky
committed
} // namespace Mantid
} // namespace Algorithms