Mantid
Loading...
Searching...
No Matches
RebinByPulseTimes.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9#include "MantidKernel/Unit.h"
11#include <algorithm>
12#include <memory>
13
14using namespace Mantid::Kernel;
15using namespace Mantid::API;
16using namespace Mantid::DataObjects;
17
18namespace Mantid::Algorithms {
19
20// Register the algorithm into the AlgorithmFactory
21DECLARE_ALGORITHM(RebinByPulseTimes)
22
23//----------------------------------------------------------------------------------------------
25const std::string RebinByPulseTimes::name() const { return "RebinByPulseTimes"; }
26
28int RebinByPulseTimes::version() const { return 1; }
29
31const std::string RebinByPulseTimes::category() const { return "Transforms\\Rebin"; }
32
33//----------------------------------------------------------------------------------------------
34
44 MantidVecPtr &XValues_new, MantidVec &OutXValues_scaled, Progress &prog) {
45
46 // workspace independent determination of length
47 const auto histnumber = static_cast<int>(inWS->getNumberHistograms());
48
49 auto x = Kernel::make_cow<HistogramData::HistogramX>(OutXValues_scaled);
50
51 PARALLEL_FOR_IF(Kernel::threadSafe(*inWS, *outputWS))
52 for (int i = 0; i < histnumber; ++i) {
54
55 const auto &el = inWS->getSpectrum(i);
56 MantidVec y_data, e_data;
57 // The EventList takes care of histogramming.
58 el.generateHistogramPulseTime(*XValues_new, y_data, e_data);
59
60 // Set the X axis for each output histogram
61 outputWS->setSharedX(i, x);
62
63 // Copy the data over.
64 outputWS->mutableY(i) = y_data;
65 outputWS->mutableE(i) = e_data;
66
67 // Report progress
68 prog.report(name());
70 }
72}
73
80 uint64_t timeMax = static_cast<uint64_t>(ws->getPulseTimeMax().totalNanoseconds());
81
82 if (timeMax == getMinX(ws)) {
83 timeMax += static_cast<uint64_t>(ws->getTofMax() * 1e3);
84 }
85 return timeMax;
86}
87
94 return ws->getPulseTimeMin().totalNanoseconds();
95}
96
97} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
Definition: MultiThreaded.h:94
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
Helper class for reporting progress from algorithms.
Definition: Progress.h:25
RebinByPulseTimes : Rebin an input EventWorkspace according to the pulse times of the events.
const std::string category() const override
Algorithm's category for identification.
uint64_t getMaxX(Mantid::API::IEventWorkspace_sptr) const override
Get the minimum x across all spectra in workspace.
void doHistogramming(Mantid::API::IEventWorkspace_sptr inWS, Mantid::API::MatrixWorkspace_sptr outputWS, Mantid::MantidVecPtr &XValues_new, Mantid::MantidVec &OutXValues_scaled, Mantid::API::Progress &prog) override
Do the algorithm specific histogramming.
uint64_t getMinX(Mantid::API::IEventWorkspace_sptr) const override
Get the maximum x across all spectra in workspace.
const std::string name() const override
Algorithm's name for identification.
int version() const override
Algorithm's version for identification.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
Definition: ProgressBase.h:51
Implements a copy on write data template.
Definition: cow_ptr.h:41
std::shared_ptr< IEventWorkspace > IEventWorkspace_sptr
shared pointer to Mantid::API::IEventWorkspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
Definition: MultiThreaded.h:22
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Definition: cow_ptr.h:172
STL namespace.