45 "An input workspace that contains a Sample log property, and "
46 "a proton charge property.");
49 "If true, the proton charge and the log "
50 "value time series are assumed to start at "
62 if (logname.empty()) {
63 throw std::runtime_error(
"Failed to supply a LogName");
65 if (!inputWS->run().hasProperty(logname)) {
66 throw std::runtime_error(
"There is no property " + logname +
" in the workspace.");
71 throw std::runtime_error(
"Problem reading property " + logname);
76 throw std::runtime_error(
"Problem reading the proton charge property");
79 double average(0),
error(0), protoncharge(0);
84 std::vector<double> stime = slog->timesAsVectorSeconds();
85 std::vector<double> svalue = slog->valuesAsVector();
90 svalue.emplace_back(0.0);
92 pcvalue.emplace_back(0.0);
94 auto isvalue = svalue.begin(), ipctime = pctime.begin(), ipcvalue = pcvalue.begin();
96 for (
auto istime = stime.begin(); istime < (--stime.end()); ++istime) {
98 while ((*ipctime) < (*istime) + diffSeconds) {
104 while ((*ipctime) < (*(istime + 1)) + diffSeconds) {
105 protoncharge += (*ipcvalue);
106 average += (*ipcvalue) * (*isvalue);
107 error += (*ipcvalue) * (*isvalue) * (*isvalue);
114 if (protoncharge != 0) {
115 g_log.
warning() <<
"Proton charge is 0. Average and standard deviations are NANs\n";
117 g_log.
debug() <<
"Sum = " << average <<
"\nSum squares = " <<
error <<
"\nPC = " << protoncharge <<
'\n';
118 average /= protoncharge;
119 error /= protoncharge;
120 error = std::sqrt(std::fabs(
error - average * average));
122 g_log.
information() <<
"Average value of " << logname <<
" is " << average <<
" +/- " <<
error <<
'\n';
#define DECLARE_ALGORITHM(classname)
int64_t total_nanoseconds(const DateAndTime &self)
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.
A property class for workspaces.
~AverageLogData() override
Destructor.
const std::string name() const override
Algorithm's name for identification.
AverageLogData()
Constructor.
const std::string category() const override
Algorithm's category for identification.
int version() const override
Algorithm's version for identification.
void init() override
Initialize the algorithm's properties.
void exec() override
Execute the algorithm.
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 warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
A specialised Property class for holding a series of time-value pairs.
std::vector< TYPE > valuesAsVector() const
Return the time series's values (unfiltered) as a vector<TYPE>
Types::Core::DateAndTime firstTime() const
Returns the first time regardless of filter.
std::vector< double > timesAsVectorSeconds() const
Return the series as list of times, where the time is the number of seconds since the start.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.