/
RebinByPulseTimes.cpp
97 lines (79 loc) · 3.06 KB
/
RebinByPulseTimes.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "MantidAlgorithms/RebinByPulseTimes.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidKernel/VectorHelper.h"
#include "MantidKernel/Unit.h"
#include <boost/make_shared.hpp>
#include <algorithm>
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
namespace Mantid {
namespace Algorithms {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(RebinByPulseTimes)
//----------------------------------------------------------------------------------------------
/// Algorithm's name for identification. @see Algorithm::name
const std::string RebinByPulseTimes::name() const {
return "RebinByPulseTimes";
}
/// Algorithm's version for identification. @see Algorithm::version
int RebinByPulseTimes::version() const { return 1; }
/// Algorithm's category for identification. @see Algorithm::category
const std::string RebinByPulseTimes::category() const {
return "Transforms\\Rebin";
}
//----------------------------------------------------------------------------------------------
/**
* Do histogramming of the data to create the output workspace.
* @param inWS : input workspace
* @param outputWS : output workspace
* @param XValues_new : Pointer to new x values vector (cowp)
* @param OutXValues_scaled : Vector of new x values
* @param prog : Progress object
*/
void RebinByPulseTimes::doHistogramming(IEventWorkspace_sptr inWS,
MatrixWorkspace_sptr outputWS,
MantidVecPtr &XValues_new,
MantidVec &OutXValues_scaled,
Progress &prog) {
// workspace independent determination of length
const int histnumber = static_cast<int>(inWS->getNumberHistograms());
auto x = Kernel::make_cow<HistogramData::HistogramX>(OutXValues_scaled);
PARALLEL_FOR2(inWS, outputWS)
for (int i = 0; i < histnumber; ++i) {
PARALLEL_START_INTERUPT_REGION
const auto &el = inWS->getSpectrum(i);
MantidVec y_data, e_data;
// The EventList takes care of histogramming.
el.generateHistogramPulseTime(*XValues_new, y_data, e_data);
// Set the X axis for each output histogram
outputWS->setX(i, x);
// Copy the data over.
outputWS->dataY(i).assign(y_data.begin(), y_data.end());
outputWS->dataE(i).assign(e_data.begin(), e_data.end());
// Report progress
prog.report(name());
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
}
/**
* get Maximum x value across all spectrum
* @param ws : workspace to inspect
* @return max time since epoch in nanoseconds.
*/
uint64_t
RebinByPulseTimes::getMaxX(Mantid::API::IEventWorkspace_sptr ws) const {
return ws->getPulseTimeMax().totalNanoseconds();
}
/**
* get Minimum x value across all spectrum
* @param ws : workspace to inspect
* @return min time since epoch in nanoseconds.
*/
uint64_t
RebinByPulseTimes::getMinX(Mantid::API::IEventWorkspace_sptr ws) const {
return ws->getPulseTimeMin().totalNanoseconds();
}
} // namespace Algorithms
} // namespace Mantid