Mantid
Loading...
Searching...
No Matches
RebinByTimeAtSample.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 +
10#include "MantidKernel/Unit.h"
11#include "MantidKernel/V3D.h"
13
14#include <memory>
15
16#include <algorithm>
17#include <cmath>
18
19namespace Mantid {
20using namespace HistogramData;
21
22namespace Algorithms {
23using namespace Mantid::Kernel;
24using namespace Mantid::API;
25using namespace Mantid::DataObjects;
26
27// Register the algorithm into the AlgorithmFactory
28DECLARE_ALGORITHM(RebinByTimeAtSample)
29
30//----------------------------------------------------------------------------------------------
31
32
33int RebinByTimeAtSample::version() const { return 1; }
34
36const std::string RebinByTimeAtSample::category() const { return "Transforms\\Rebin;Events\\EventFiltering"; }
37
39const std::string RebinByTimeAtSample::summary() const {
40 return "Rebins with an x-axis of relative time at sample for comparing event "
41 "arrival time at the sample environment.";
42}
43
44const std::string RebinByTimeAtSample::name() const { return "RebinByTimeAtSample"; }
45
55 MantidVecPtr &XValues_new, MantidVec &OutXValues_scaled, Progress &prog) {
56 const auto histnumber = static_cast<int>(inWS->getNumberHistograms());
57
58 const double tofOffset = 0;
59
60 TimeAtSampleStrategyElastic strategy(inWS);
61
62 auto x = Kernel::make_cow<HistogramData::HistogramX>(OutXValues_scaled);
63
64 // Go through all the histograms and set the data
65 PARALLEL_FOR_IF(Kernel::threadSafe(*inWS, *outputWS))
66 for (int i = 0; i < histnumber; ++i) {
68
69 Correction correction = strategy.calculate(i);
70
71 const double tofFactor = correction.factor;
72
73 const auto &el = inWS->getSpectrum(i);
74 MantidVec y_data, e_data;
75 // The EventList takes care of histogramming.
76 el.generateHistogramTimeAtSample(*XValues_new, y_data, e_data, tofFactor, tofOffset);
77
78 // Set the X axis for each output histogram
79 outputWS->setSharedX(i, x);
80
81 // Copy the data over.
82 outputWS->mutableY(i) = y_data;
83 outputWS->mutableE(i) = e_data;
84
85 // Report progress
86 prog.report(name());
88 }
90}
91
98 return ws->getTimeAtSampleMax().totalNanoseconds();
99}
100
107 return ws->getTimeAtSampleMin().totalNanoseconds();
108}
109
110} // namespace Algorithms
111} // namespace Mantid
#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
RebinByTimeAtSample : Rebins an event workspace to a histogram workspace with time at sample along th...
const std::string category() const override
Algorithm's category for identification.
const std::string name() const override
function to return a name of the algorithm, must be overridden in all algorithms
uint64_t getMaxX(Mantid::API::IEventWorkspace_sptr ws) 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 histogramming of the data to create the output workspace.
uint64_t getMinX(Mantid::API::IEventWorkspace_sptr ws) const override
Get the maximum x across all spectra in workspace.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
TimeAtSampleStrategyElastic : Time at sample stragegy for elastic scattering.
Correction calculate(const size_t &workspace_index) const override
Calculate correction.
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
Helper class which provides the Collimation Length for SANS instruments.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Definition: cow_ptr.h:172
The Correction struct to be applied as factor * TOF + offset offset:: TOF offset in unit of TOF facto...