Mantid
Loading...
Searching...
No Matches
LogarithmScale.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 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
10#include <cmath>
11#include <stdexcept>
12
15#include "MantidKernel/Logger.h"
16
17namespace Mantid::API {
18namespace {
20Kernel::Logger g_log("LogarithmScale");
21} // namespace
22
23DECLARE_TRANSFORMSCALE(LogarithmScale)
24
25void LogarithmScale::setBase(const double base) {
26 if (base <= 0) {
27 g_log.error("Error: logarithm base must be a positive number");
28 }
29 m_base = base;
30}
31
32/* Transform the grid to adopt a logarithm scale.
33 * @param gd a grid object
34 */
35void LogarithmScale::transform(std::vector<double> &gd) {
36 double a = 1.0 / log(m_base);
37 size_t n = gd.size();
38 if (n == 0)
39 return; // no need to process
40 if (gd.front() <= 0) {
41 g_log.error("LogarithmScale::transform Error: negative values");
42 return;
43 }
44 if (n < 3)
45 return; // no need to process
46 double startX = a * log(gd.front());
47 double endX = a * log(gd.back());
48 double spacing = (endX - startX) / double(n);
49
50 double x = startX + spacing;
51 for (auto it = gd.begin() + 1; it != gd.end() - 1; it++) {
52 *it = pow(m_base, x);
53 x += spacing;
54 }
55}
56
57} // namespace Mantid::API
#define DECLARE_TRANSFORMSCALE(classname)
double m_base
The scaling transformation.
void transform(std::vector< double > &gd) override
The scaling transformation. Define in derived classes.
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
Kernel::Logger g_log("ExperimentInfo")
static logger object