Mantid
Loading...
Searching...
No Matches
Logarithm.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
10using namespace Mantid::API;
11using namespace Mantid::Kernel;
12
13#include <cmath>
14namespace Mantid::Algorithms {
15// Register the class into the algorithm factory
16DECLARE_ALGORITHM(Logarithm)
17
18Logarithm::Logarithm() : UnaryOperation(), log_Min(0), is_natural(true) { this->useHistogram = true; }
19
21 declareProperty("Filler", 0.0,
22 "The value that will be placed into the "
23 "output workspace if an input value is equal "
24 "or less than 0. Default value is 0");
25 declareProperty("Natural", true,
26 "Logical value which specifies if user "
27 "wants to calculate natural or base 10 "
28 "logarithm.");
29}
30
32 this->log_Min = getProperty("Filler");
33 this->is_natural = getProperty("Natural");
34}
35
36void Logarithm::performUnaryOperation(const double XIn, const double YIn, const double EIn, double &YOut,
37 double &EOut) {
38 (void)XIn; // Avoid compiler warning
39 if (YIn <= 0) {
40 YOut = this->log_Min;
41 EOut = 0;
42 } else {
43 if (this->is_natural) {
44 YOut = std::log(YIn);
45 EOut = EIn / YIn;
46 } else {
47 YOut = std::log10(YIn);
48 EOut = 0.434 * EIn / YIn;
49 }
50 }
51}
52
53} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
Takes a workspace as input and calculates the natural logarithm of number of counts for each 1D spect...
Definition: Logarithm.h:36
void defineProperties() override
Declare additional properties for this algorithm.
Definition: Logarithm.cpp:20
void performUnaryOperation(const double XIn, const double YIn, const double EIn, double &YOut, double &EOut) override
Actually the function, which is run on values when the operation is performed.
Definition: Logarithm.cpp:36
double log_Min
The value to replace ln(0)
Definition: Logarithm.h:56
void retrieveProperties() override
get properties from GUI
Definition: Logarithm.cpp:31
bool is_natural
If the logarithm natural or 10-based.
Definition: Logarithm.h:58
UnaryOperation supports the implementation of a Unary operation on an input workspace.