-
Notifications
You must be signed in to change notification settings - Fork 122
/
RebinByTimeAtSample.cpp
111 lines (87 loc) · 3.71 KB
/
RebinByTimeAtSample.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// 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/RebinByTimeAtSample.h"
#include "MantidAlgorithms/TimeAtSampleStrategyElastic.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidKernel/Unit.h"
#include "MantidKernel/V3D.h"
#include "MantidKernel/VectorHelper.h"
#include <memory>
#include <algorithm>
#include <cmath>
namespace Mantid {
using namespace HistogramData;
namespace Algorithms {
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(RebinByTimeAtSample)
//----------------------------------------------------------------------------------------------
/// Algorithm's version for identification. @see Algorithm::version
int RebinByTimeAtSample::version() const { return 1; }
/// Algorithm's category for identification. @see Algorithm::category
const std::string RebinByTimeAtSample::category() const { return "Transforms\\Rebin;Events\\EventFiltering"; }
/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary
const std::string RebinByTimeAtSample::summary() const {
return "Rebins with an x-axis of relative time at sample for comparing event "
"arrival time at the sample environment.";
}
const std::string RebinByTimeAtSample::name() const { return "RebinByTimeAtSample"; }
/**
* 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 RebinByTimeAtSample::doHistogramming(IEventWorkspace_sptr inWS, MatrixWorkspace_sptr outputWS,
MantidVecPtr &XValues_new, MantidVec &OutXValues_scaled, Progress &prog) {
const auto histnumber = static_cast<int>(inWS->getNumberHistograms());
const double tofOffset = 0;
TimeAtSampleStrategyElastic strategy(inWS);
auto x = Kernel::make_cow<HistogramData::HistogramX>(OutXValues_scaled);
// Go through all the histograms and set the data
PARALLEL_FOR_IF(Kernel::threadSafe(*inWS, *outputWS))
for (int i = 0; i < histnumber; ++i) {
PARALLEL_START_INTERRUPT_REGION
Correction correction = strategy.calculate(i);
const double tofFactor = correction.factor;
const auto &el = inWS->getSpectrum(i);
MantidVec y_data, e_data;
// The EventList takes care of histogramming.
el.generateHistogramTimeAtSample(*XValues_new, y_data, e_data, tofFactor, tofOffset);
// 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 RebinByTimeAtSample::getMaxX(Mantid::API::IEventWorkspace_sptr ws) const {
return ws->getTimeAtSampleMax().totalNanoseconds();
}
/**
* get Minimum x value across all spectrum
* @param ws : workspace to inspect
* @return min time since epoch in nanoseconds.
*/
uint64_t RebinByTimeAtSample::getMinX(Mantid::API::IEventWorkspace_sptr ws) const {
return ws->getTimeAtSampleMin().totalNanoseconds();
}
} // namespace Algorithms
} // namespace Mantid