27using namespace Kernel;
33 "The input EventWorkspace. Must contain 'raw' (unweighted) events");
36 "A workspace containing the monitor counts relating to the input "
39 "The name of the workspace to be created as the output of "
40 "the algorithm. The output workspace will be a "
41 "[[TableWorkspace]] in the case that a log holding integer "
42 "values is given, and a single-spectrum [[Workspace2D]] "
46 "The name of the number series log against which the data "
49 std::make_unique<
ArrayProperty<double>>(
"OutputBinning",
"", std::make_shared<RebinParamsValidator>(
true)),
50 "Binning parameters for the output workspace (see [[Rebin]] for syntax) "
51 "(Optional for logs holding integer values, mandatory otherwise)");
55 std::map<std::string, std::string> errors;
67 errors[
"InputWorkspace"] =
"This algorithm only works for unweighted ('raw') events";
75 errors[
"LogName"] =
"'" +
m_logName +
"' is not a time-series log.";
78 if (log->realSize() == 0) {
79 errors[
"LogName"] =
"'" +
m_logName +
"' is empty.";
102 if (intLog !=
nullptr) {
105 throw std::invalid_argument(
"OutputBinning must be provided for floating-point number logs");
109 if (intLog !=
nullptr) {
111 }
else if (dblLog !=
nullptr) {
120 throw std::runtime_error(
"This algorithm only supports number-series logs");
133 const int xLength = maxVal - minVal + 1;
135 if (xLength > 10000) {
136 g_log.
warning() <<
"Did you really want to create a " << xLength <<
" row table? This will take some time!\n";
140 std::vector<int>
Y(xLength);
141 const auto numSpec =
static_cast<int>(
m_inputWorkspace->getNumberHistograms());
142 Progress prog(
this, 0.0, 1.0, numSpec + xLength);
144 for (
int spec = 0; spec < numSpec; ++spec) {
155 auto logValues = outputWorkspace->addColumn(
"int",
m_logName);
156 auto counts = outputWorkspace->addColumn(
"int",
"Counts");
157 auto errors = outputWorkspace->addColumn(
"double",
"Error");
158 outputWorkspace->setRowCount(xLength);
160 logValues->setPlotType(1);
161 counts->setPlotType(2);
162 errors->setPlotType(5);
165 for (
int i = 0; i < xLength; ++i) {
166 logValues->cell<
int>(i) = minVal + i;
167 counts->cell<
int>(i) =
Y[i];
168 errors->cell<
double>(i) = std::sqrt(
Y[i]);
175 auto timeCol = outputWorkspace->addColumn(
"double",
"time");
178 auto protonChgCol = outputWorkspace->addColumn(
"double",
"proton_charge");
182 protonChargeLog =
m_inputWorkspace->run().getTimeSeriesProperty<
double>(
"proton_charge");
184 if (protonChargeLog->
realSize() == 0)
185 protonChargeLog =
nullptr;
186 }
catch (std::exception &) {
188 g_log.
warning(
"proton_charge log not found in workspace.");
194 for (
auto &otherLog : otherLogs) {
195 auto newColumn = outputWorkspace->addColumn(
"double", otherLog.first);
198 newColumn->setPlotType(1);
204 const int row =
value - minVal;
217 double duration = 0.0;
218 for (
auto &time : filter) {
219 duration += time.duration();
221 timeCol->cell<
double>(row) = duration;
226 protonChgCol->cell<
double>(row) =
sumProtonCharge(protonChargeLog, filter);
229 for (
auto &otherLog : otherLogs) {
234 outputWorkspace->getColumn(otherLog.first)->cell<
double>(row) = otherLog.second->averageValueInFilter(filter);
259 for (
auto pulseTime : pulseTimes) {
268 if (logValue >= minVal && logValue <= maxVal) {
271 ++
Y[logValue - minVal];
288 if (!monitorWorkspace)
291 const auto &spectrumInfo = monitorWorkspace->spectrumInfo();
293 const int xLength = maxVal - minVal + 1;
295 for (std::size_t spec = 0; spec < monitorWorkspace->getNumberHistograms(); ++spec) {
298 const std::string monitorName = spectrumInfo.detector(spec).getName();
299 auto monitorCounts = outputWorkspace->addColumn(
"int", monitorName);
300 const IEventList &eventList = monitorWorkspace->getSpectrum(spec);
303 std::vector<int>
Y(xLength);
306 for (
int i = 0; i < xLength; ++i) {
307 monitorCounts->cell<
int>(i) =
Y[i];
324 std::vector<std::pair<std::string, const Kernel::ITimeSeriesProperty *>> numberSeriesProps;
326 for (
auto log : logs) {
327 const std::string logName = log->name();
333 if (logName ==
"proton_charge")
345 numberSeriesProps.emplace_back(logName, tsp);
349 return numberSeriesProps;
360 std::unique_ptr<Kernel::TimeSeriesProperty<double>> protonChargeLogClone(protonChargeLog->
clone());
361 protonChargeLogClone->filterByTimes(filter);
363 const std::vector<double> pcValues = protonChargeLogClone->valuesAsVector();
364 return std::accumulate(pcValues.begin(), pcValues.end(), 0.0);
379 std::vector<double> XValues;
381 assert((
int)XValues.size() == XLength);
386 outputWorkspace->mutableX(0) = XValues;
387 outputWorkspace->getAxis(0)->title() =
m_logName;
388 outputWorkspace->setYUnit(
"Counts");
390 auto &
Y = outputWorkspace->mutableY(0);
391 const auto numSpec =
static_cast<int>(
m_inputWorkspace->getNumberHistograms());
392 Progress prog(
this, 0.0, 1.0, numSpec);
394 for (
int spec = 0; spec < numSpec; ++spec) {
397 const auto pulseTimes = eventList.getPulseTimes();
398 for (
auto pulseTime : pulseTimes) {
401 if (logValue >= XValues.front() && logValue < XValues.back()) {
414 std::transform(
Y.cbegin(),
Y.cend(), outputWorkspace->mutableE(0).begin(), (double (*)(
double))std::sqrt);
#define DECLARE_ALGORITHM(classname)
double value
The value of the point.
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void interruption_point()
This is called during long-running operations, and check if the algorithm has requested that it be ca...
IEventList : Interface to Mantid::DataObjects::EventList class, used to expose to PythonAPI.
virtual std::vector< Mantid::Types::Core::DateAndTime > getPulseTimes() const =0
Return the list of pulse time values.
Helper class for reporting progress from algorithms.
A property class for workspaces.
void init() override
Virtual method - must be overridden by concrete algorithm.
std::vector< double > m_binningParams
The optional binning parameters.
void addMonitorCounts(const API::ITableWorkspace_sptr &outputWorkspace, const Kernel::TimeSeriesProperty< int > *log, const int minVal, const int maxVal)
Looks for monitor event data and, if found, adds columns to the output table corresponding to the mon...
void filterEventList(const API::IEventList &eventList, const int minVal, const int maxVal, const Kernel::TimeSeriesProperty< int > *log, std::vector< int > &Y)
Goes through an event list assigning events to the output vector according to the log value at the ti...
void exec() override
Virtual method - must be overridden by concrete algorithm.
double sumProtonCharge(const Kernel::TimeSeriesProperty< double > *protonChargeLog, const Kernel::TimeSplitterType &filter)
Integrates the proton charge between specified times.
std::map< std::string, std::string > validateInputs() override
Method checking errors on ALL the inputs, before execution.
void createBinnedOutput(const Kernel::TimeSeriesProperty< T > *log)
Create a single-spectrum Workspace2D containing the integrated counts versus log value,...
void createTableOutput(const Kernel::TimeSeriesProperty< int > *log)
Produces the table workspace output for an integer TimeSeriesProperty.
std::string m_logName
The name of the log to sum against.
DataObjects::EventWorkspace_const_sptr m_inputWorkspace
The input workspace.
std::vector< std::pair< std::string, const Kernel::ITimeSeriesProperty * > > getNumberSeriesLogs()
Searches the input workspace for int or double TimeSeriesProperty's other than the one being summed a...
Support for a property that holds an array of values.
Exception for when an item is not found in a collection.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
A non-templated interface to a TimeSeriesProperty.
void warning(const std::string &msg)
Logs at warning level.
Validator to check that a property is not left empty.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
Base class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Represents a time interval.
A specialised Property class for holding a series of time-value pairs.
TimeSeriesProperty< TYPE > * clone() const override
"Virtual" copy constructor
TYPE minValue() const
Returns the minimum value found in the series.
TYPE maxValue() const
Returns the maximum value found in the series.
void makeFilterByValue(std::vector< SplittingInterval > &split, double min, double max, double TimeTolerance=0.0, bool centre=false) const override
Fill a TimeSplitterType that will filter the events by matching.
void expandFilterToRange(std::vector< SplittingInterval > &split, double min, double max, const TimeInterval &range) const override
Make sure an existing filter covers the full time range given.
Types::Core::DateAndTime lastTime() const
Returns the last time.
TYPE lastValue() const
Returns the last value.
TYPE getSingleValue(const Types::Core::DateAndTime &t) const
Returns the value at a particular time.
int realSize() const override
Returns the real size of the time series property map:
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
MANTID_KERNEL_DLL int getBinIndex(const std::vector< double > &bins, const double value)
Return the index into a vector of bin boundaries for a particular X value.
int MANTID_KERNEL_DLL createAxisFromRebinParams(const std::vector< double > ¶ms, std::vector< double > &xnew, const bool resize_xnew=true, const bool full_bins_only=false, const double xMinHint=std::nan(""), const double xMaxHint=std::nan(""), const bool useReverseLogarithmic=false, const double power=-1)
Creates a new output X array given a 'standard' set of rebinning parameters.
std::vector< SplittingInterval > TimeSplitterType
A typedef for splitting events according their pulse time.
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
@ Input
An input workspace.
@ Output
An output workspace.