/
RebinByPulseTimes.cpp
97 lines (78 loc) · 3.35 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
// 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 +
#include "MantidAlgorithms/RebinByPulseTimes.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidKernel/Unit.h"
#include "MantidKernel/VectorHelper.h"
#include <algorithm>
#include <memory>
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
namespace Mantid::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 auto histnumber = static_cast<int>(inWS->getNumberHistograms());
auto x = Kernel::make_cow<HistogramData::HistogramX>(OutXValues_scaled);
PARALLEL_FOR_IF(Kernel::threadSafe(*inWS, *outputWS))
for (int i = 0; i < histnumber; ++i) {
PARALLEL_START_INTERRUPT_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->setSharedX(i, x);
// Copy the data over.
outputWS->mutableY(i) = y_data;
outputWS->mutableE(i) = e_data;
// Report progress
prog.report(name());
PARALLEL_END_INTERRUPT_REGION
}
PARALLEL_CHECK_INTERRUPT_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 {
uint64_t timeMax = static_cast<uint64_t>(ws->getPulseTimeMax().totalNanoseconds());
if (timeMax == getMinX(ws)) {
timeMax += static_cast<uint64_t>(ws->getTofMax() * 1e3);
}
return timeMax;
}
/**
* 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 Mantid::Algorithms