21using namespace Kernel;
23using DataObjects::EventWorkspace;
30const std::string INT_CHARGE_NAME(
"gd_prtn_chrg");
32const std::string LOG_CHARGE_NAME(
"proton_charge");
47 "An event workspace");
49 "The name to use for the output workspace");
50 auto range = std::make_shared<BoundedValidator<double>>();
51 range->setBounds(0., 100.);
52 declareProperty(
"LowerCutoff", 95., range,
"The percentage of the average to use as the lower bound");
61 const API::Run &runlogs = inputWS->run();
67 throw std::runtime_error(
"Found no integrated charge value in " + INT_CHARGE_NAME);
70 this->
g_log.
warning() <<
"Failed to find \"" << INT_CHARGE_NAME <<
"\" in run object.\n";
75 throw std::runtime_error(
"Failed to find \"" + LOG_CHARGE_NAME +
"\" in sample logs");
79 throw std::logic_error(
"Failed to find \"" + LOG_CHARGE_NAME +
"\" in sample logs");
85 throw std::runtime_error(
"Maximum value of charge is not greater than zero (" + LOG_CHARGE_NAME +
")");
89 double min_percent = this->
getProperty(
"LowerCutoff");
91 double min_pcharge = stats.
mean * min_percent;
92 double max_pcharge = stats.
maximum * 1.1;
93 if (min_pcharge >= max_pcharge) {
94 throw std::runtime_error(
"proton_charge window filters out all of the data");
96 this->
g_log.
information() <<
"Filtering pcharge outside of " << min_pcharge <<
" to " << max_pcharge <<
'\n';
97 size_t inputNumEvents = inputWS->getNumberEvents();
102 filterAlgo->setProperty(
"InputWorkspace", inputWS);
103 filterAlgo->setProperty(
"LogName",
"proton_charge");
104 filterAlgo->setProperty(
"MinimumValue", min_pcharge);
105 filterAlgo->setProperty(
"MaximumValue", max_pcharge);
106 filterAlgo->execute();
110 size_t outputNumEvents = outputWS->getNumberEvents();
114 double percent =
static_cast<double>(inputNumEvents - outputNumEvents) /
static_cast<double>(inputNumEvents);
117 this->
g_log.
warning() <<
"Deleted " << (inputNumEvents - outputNumEvents) <<
" of " << inputNumEvents <<
" events ("
118 <<
static_cast<int>(percent) <<
"%)\n";
120 this->
g_log.
notice() <<
"Deleted " << (inputNumEvents - outputNumEvents) <<
" of " << inputNumEvents <<
" events ("
121 <<
static_cast<float>(percent) <<
"%)"
122 <<
" by proton charge from " << min_pcharge <<
" to " << max_pcharge
123 <<
" with mean = " << stats.
mean <<
"\n";
#define DECLARE_ALGORITHM(classname)
double value
The value of the point.
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.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
bool hasProperty(const std::string &name) const
Does the property exist on the object.
Kernel::Property * getLogData(const std::string &name) const
Access a single log entry.
HeldType getPropertyValueAsType(const std::string &name) const
Get the value of a property as the given TYPE.
This class stores information regarding an experimental run as a series of log entries.
A property class for workspaces.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
void exec() override
Executes the algorithm.
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
void init() override
Initialise the properties.
int version() const override
Algorithm's version for identification overriding a virtual method.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice 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::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
@ Input
An input workspace.
@ Output
An output workspace.
Struct holding some useful statistics for a TimeSeriesProperty.
double maximum
Maximum value.