Logarithm.cpp 1.77 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#include "MantidAlgorithms/Logarithm.h"
Alex Buts's avatar
Alex Buts committed
8
9
10
11
12
#include "MantidAPI/WorkspaceProperty.h"

using namespace Mantid::API;
using namespace Mantid::Kernel;

13
#include <cmath>
14
15
namespace Mantid {
namespace Algorithms {
16
17
18
// Register the class into the algorithm factory
DECLARE_ALGORITHM(Logarithm)

19
20
Logarithm::Logarithm() : UnaryOperation(), log_Min(0), is_natural(true) {
  this->useHistogram = true;
21
22
}

23
void Logarithm::defineProperties() {
LamarMoore's avatar
LamarMoore committed
24
25
26
27
28
29
  declareProperty("Filler", 0.0,
                  "The value that will be placed into the "
                  "output workspace if an input value is equal "
                  "or less than 0. Default value is 0");
  declareProperty("Natural", true,
                  "Logical value which specifies if user "
30
                  "wants to calculate natural or base 10 "
LamarMoore's avatar
LamarMoore committed
31
                  "logarithm.");
32
}
33

34
35
36
void Logarithm::retrieveProperties() {
  this->log_Min = getProperty("Filler");
  this->is_natural = getProperty("Natural");
37
38
}

39
40
41
42
43
void Logarithm::performUnaryOperation(const double XIn, const double YIn,
                                      const double EIn, double &YOut,
                                      double &EOut) {
  (void)XIn; // Avoid compiler warning
  if (YIn <= 0) {
44
45
    YOut = this->log_Min;
    EOut = 0;
46
47
  } else {
    if (this->is_natural) {
48
      YOut = std::log(YIn);
49
50
      EOut = EIn / YIn;
    } else {
51
      YOut = std::log10(YIn);
52
      EOut = 0.434 * EIn / YIn;
53
    }
54
55
  }
}
56

57
58
} // End Namespace Algorithms
} // End Namespace Mantid