-
Notifications
You must be signed in to change notification settings - Fork 122
/
SortEvents.cpp
71 lines (60 loc) · 2.52 KB
/
SortEvents.cpp
1
2
3
4
5
6
7
8
9
10
11
12
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
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAlgorithms/SortEvents.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/ListValidator.h"
namespace Mantid {
namespace Algorithms {
// Register the class into the algorithm factory
DECLARE_ALGORITHM(SortEvents)
using namespace Kernel;
using namespace API;
using DataObjects::EventWorkspace;
using DataObjects::EventWorkspace_const_sptr;
using DataObjects::EventWorkspace_sptr;
/** Initialisation method. Declares properties to be used in algorithm.
*
*/
void SortEvents::init() {
declareProperty(std::make_unique<WorkspaceProperty<EventWorkspace>>("InputWorkspace", "", Direction::InOut),
"EventWorkspace to be sorted.");
std::vector<std::string> propOptions{"X Value", "Pulse Time", "Pulse Time + TOF"};
declareProperty("SortBy", "X Value", std::make_shared<StringListValidator>(propOptions),
"How to sort the events:\n"
" X Value: the x-position of the event in each pixel "
"(typically Time of Flight).\n"
" Pulse Time: the wall-clock time of the pulse that "
"produced the event.");
}
/** Executes the rebin algorithm
*
* @throw runtime_error Thrown if the bin range does not intersect the range of
*the input workspace
*/
void SortEvents::exec() {
// Get the input workspace
EventWorkspace_sptr eventW = getProperty("InputWorkspace");
// And other properties
std::string sortoption = getPropertyValue("SortBy");
//------- EventWorkspace ---------------------------
const size_t histnumber = eventW->getNumberHistograms();
// Initialize progress reporting.
Progress prog(this, 0.0, 1.0, histnumber);
DataObjects::EventSortType sortType = DataObjects::TOF_SORT;
if (sortoption == "Pulse Time")
sortType = DataObjects::PULSETIME_SORT;
else if (sortoption == "Pulse Time + TOF")
sortType = DataObjects::PULSETIMETOF_SORT;
// This runs the SortEvents algorithm in parallel
eventW->sortAll(sortType, &prog);
}
} // namespace Algorithms
} // namespace Mantid