18using namespace Kernel;
20using HistogramData::Histogram;
24 "Name of the input workspace");
26 "The name of the workspace to be created as the output of the algorithm");
27 std::vector<int> npts0{3};
28 auto min = std::make_shared<Kernel::ArrayBoundedValidator<int>>();
32 "The number of points to average over (minimum 3). If an even number is\n"
33 "given, it will be incremented by 1 to make it odd (default value 3)");
36 "Optional: GroupingWorkspace to use for vector of NPoints.");
43 std::vector<int> nptsGroup =
getProperty(
"NPoints");
48 groupWS->makeDetectorIDToGroupVector(
udet2group, nGroups);
53 const auto vecSize =
static_cast<int>(
inputWorkspace->blocksize());
60 for (
int i = 0; i < static_cast<int>(
inputWorkspace->getNumberHistograms()); ++i) {
62 int npts = nptsGroup[0];
69 npts = nptsGroup[group - 1];
72 if (npts >= vecSize) {
73 g_log.
error(
"The number of averaging points requested is larger than the "
75 throw std::out_of_range(
"The number of averaging points requested is "
76 "larger than the spectrum length");
103 const auto &dets =
inputWorkspace->getSpectrum(wi).getDetectorIDs();
106 g_log.
debug() << wi <<
" <- this workspace index is empty!\n";
110 auto it = dets.cbegin();
119 for (; it != dets.end(); ++it)
132Histogram
smooth(
const Histogram &histogram,
int npts) {
135 int halfWidth = (npts - 1) / 2;
137 Histogram smoothed(histogram);
139 const auto &
Y = histogram.y();
140 const auto &E = histogram.e();
141 auto &newY = smoothed.mutableY();
142 auto &newE = smoothed.mutableE();
144 double total = 0.0, totalE = 0.0;
146 for (
int k = 0; k < halfWidth; ++k) {
149 totalE += E[k] * E[k];
154 for (
int j = 0; j <= halfWidth; ++j) {
155 const int index = j + halfWidth;
158 newY[j] = total / (
index + 1);
160 newE[j] = sqrt(totalE) / (
index + 1);
167 const auto vecSize =
static_cast<int>(histogram.size());
168 for (
int k = halfWidth + 1; k < vecSize - halfWidth; ++k) {
169 const int kp = k + halfWidth;
170 const int km = k - halfWidth - 1;
171 total += (
Y[kp] !=
Y[kp] ? 0.0 :
Y[kp]) - (
Y[km] !=
Y[km] ? 0.0 :
Y[km]);
172 newY[k] = total / npts;
173 totalE += E[kp] * E[kp] - E[km] * E[km];
177 newE[k] = std::sqrt(std::abs(totalE)) / npts;
180 for (
int l = vecSize - halfWidth; l < vecSize; ++l) {
181 const int index = l - halfWidth;
183 newY[l] = total / (vecSize -
index);
185 newE[l] = std::sqrt(std::abs(totalE)) / (vecSize -
index);
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
#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...
#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.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Helper class for reporting progress from algorithms.
A property class for workspaces.
std::vector< int > udet2group
void init() override
Initialisation code.
API::MatrixWorkspace_const_sptr inputWorkspace
int validateSpectrumInGroup(size_t wi)
Verify that all the contributing detectors to a spectrum belongs to the same group.
void exec() override
Execution code.
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
void error(const std::string &msg)
Logs at error level.
void information(const std::string &msg)
Logs at information level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
HistogramData::Histogram smooth(const HistogramData::Histogram &histogram, int npts)
std::shared_ptr< GroupingWorkspace > GroupingWorkspace_sptr
shared pointer to the GroupingWorkspace 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.
@ Input
An input workspace.
@ Output
An output workspace.