Mantid
Loading...
Searching...
No Matches
CalculateCountRate.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 +
8
10#include "MantidAPI/Axis.h"
12#include "MantidAPI/Run.h"
15#include "MantidHistogramData/Histogram.h"
22#include "MantidKernel/Unit.h"
24
25#include <numeric>
26
27using namespace Mantid::DataObjects;
28using namespace Mantid::HistogramData;
29
30namespace Mantid::Algorithms {
31
32// Register the algorithm into the AlgorithmFactory
33DECLARE_ALGORITHM(CalculateCountRate)
34
35//----------------------------------------------------------------------------------------------
36
37
38const std::string CalculateCountRate::name() const { return "CalculateCountRate"; }
39
41int CalculateCountRate::version() const { return 1; }
42
44const std::string CalculateCountRate::category() const {
45 return "Inelastic\\Utility;Diagnostics;Events\\EventFiltering";
46}
47
49const std::string CalculateCountRate::summary() const {
50 return "Calculates instrument count rate as the function of the "
51 "experiment time and adds CountRate log to the source workspace.";
52}
53
54//----------------------------------------------------------------------------------------------
58
61 "Name of the event workspace to calculate counting rate for.");
63 "Minimal value of X-range for the rate calculations. If left "
64 "to default, Workspace X-axis minimal value is used.");
66 "Maximal value of X-range for the rate calculations. If left "
67 "to default, Workspace X-axis maximal value is used.");
69 "RangeUnits", "Energy",
70 std::make_shared<Kernel::StringListValidator>(Kernel::UnitFactory::Instance().getKeys()),
72 "The units from Mantid Unit factory for calculating the "
73 "counting rate and XMin-XMax ranges are in. If the "
74 "X-axis of the input workspace is not expressed"
75 "in these units, unit conversion will be performed, so the "
76 "workspace should contain all necessary information for this "
77 "conversion. E.g. if *RangeUnits* is *EnergyTransfer*, Ei "
78 "log containing incident energy value should be attached to the "
79 "input workspace. See ConvertUnits algorithm for the details.");
80 std::vector<std::string> propOptions{"Elastic", "Direct", "Indirect"};
81 declareProperty("EMode", "Elastic", std::make_shared<Kernel::StringListValidator>(propOptions),
82 "The energy mode for 'RangeUnits' conversion mode (default: elastic)");
83
84 // Used logs group
85 std::string used_logs_mode("Used normalization logs");
86 declareProperty("NormalizeTheRate", true,
87 "Usually you want to normalize counting rate to some "
88 "rate related to the source beam intensity. Change this to "
89 "'false' if appropriate time series log is broken || not attached to "
90 "the input workspace.");
91 declareProperty("UseLogDerivative", false,
92 "If the normalization log contains "
93 "cumulative counting, derivative "
94 "of this log is necessary to get "
95 "correct normalization values.");
96 declareProperty("NormalizationLogName", "proton_charge",
97 "The name of the log, used in the counting rate normalization. ");
98 setPropertyGroup("NormalizeTheRate", used_logs_mode);
99 setPropertyGroup("UseLogDerivative", used_logs_mode);
100 setPropertyGroup("NormalizationLogName", used_logs_mode);
101
102 // Results
103 declareProperty("CountRateLogName", "block_count_rate", std::make_shared<Kernel::MandatoryValidator<std::string>>(),
104 "The name of the processed time series log with instrument "
105 "count rate to be added"
106 " to the source workspace");
107 declareProperty("UseNormLogGranularity", true,
108 "If true, the count rate log will have the normalization log "
109 "accuracy; If false, the 'NumTimeSteps' in the visualization "
110 "workspace below will be used for the target log granularity too.");
111
112 // visualization group
113 std::string spur_vis_mode("Spurion visualization");
114 declareProperty(std::make_unique<API::WorkspaceProperty<>>("VisualizationWs", "", Kernel::Direction::Output,
116 "Optional name to build 2D matrix workspace for spurion visualization. "
117 "If name is provided, a 2D workspace with this name will be created "
118 "containing data to visualize counting rate as function of time in the "
119 "ranges XMin-XMax");
120
121 auto mustBeReasonable = std::make_shared<Kernel::BoundedValidator<int>>();
122 mustBeReasonable->setLower(3);
124 std::make_unique<Kernel::PropertyWithValue<int>>("NumTimeSteps", 200, mustBeReasonable, Kernel::Direction::Input),
125 "Number of time steps (time accuracy) the visualization workspace has. "
126 "Also number of steps in 'CountRateLogName' log if "
127 "'UseNormLogGranularity' is set to false. Should be bigger than 3");
129 std::make_unique<Kernel::PropertyWithValue<int>>("XResolution", 100, mustBeReasonable, Kernel::Direction::Input),
130 "Number of steps (accuracy) of the visualization workspace has along "
131 "X-axis. ");
132 setPropertyGroup("VisualizationWs", spur_vis_mode);
133 setPropertyGroup("NumTimeSteps", spur_vis_mode);
134 setPropertyGroup("XResolution", spur_vis_mode);
135}
136
137//----------------------------------------------------------------------------------------------
141
142 DataObjects::EventWorkspace_sptr sourceWS = getProperty("Workspace");
143 API::EventType et = sourceWS->getEventType();
145 throw std::runtime_error("Event workspace " + sourceWS->getName() +
146 " contains events without necessary frame "
147 "information. Can not process counting rate");
148 }
149
150 // Identify correct way to treat input logs and general properties of output
151 // log
152 this->setOutLogParameters(sourceWS);
153
154 //-------------------------------------
155 // identify ranges for count rate calculations and initiate source workspace
156 this->setSourceWSandXRanges(sourceWS);
157
158 // check if visualization workspace is necessary and if it is, prepare
159 // visualization workspace to use
161
162 // create results log and add it to the source workspace
163 const std::string logname = getProperty("CountRateLogName");
164 auto newlog = std::make_unique<Kernel::TimeSeriesProperty<double>>(logname);
165 // calculate averages requested and modify results log
166 this->calcRateLog(m_workingWS, newlog.get());
167 sourceWS->mutableRun().addProperty(std::move(newlog), true);
168
169 // clear up log derivative and existing log pointer (if any)
170 // to avoid incorrect usage
171 // at subsequent calls to the same algorithm.
172 m_tmpLogHolder.reset();
173 m_pNormalizationLog = nullptr;
174}
175
186 Kernel::TimeSeriesProperty<double> *const targLog) {
187
188 MantidVec countRate(m_numLogSteps);
189 std::vector<double> countNormalization;
190 if (this->normalizeCountRate())
191 countNormalization = m_pNormalizationLog->valuesAsVector();
192
193 std::unique_ptr<std::mutex[]> pVisWS_locks;
194 if (this->buildVisWS()) {
195 pVisWS_locks.reset(new std::mutex[m_visWs->getNumberHistograms()]);
196 }
197
198 auto nHist = static_cast<int64_t>(InputWorkspace->getNumberHistograms());
199 // Initialize progress reporting.
200 API::Progress prog(this, 0.0, 1.0, nHist);
201
202 auto dTRangeMin = static_cast<double>(m_TRangeMin.totalNanoseconds());
203 auto dTRangeMax = static_cast<double>(m_TRangeMax.totalNanoseconds());
204 // The variable is used by a parallel code so this behaviour is desired
205 // cppcheck-suppress variableScope
206 std::vector<MantidVec> Buff;
207
208#pragma omp parallel
209 {
210 int nThreads = PARALLEL_NUMBER_OF_THREADS;
211#pragma omp single
212 {
213 // initialize thread's histogram buffer
214 Buff.resize(nThreads);
215 }
216 auto nThread = PARALLEL_THREAD_NUMBER;
217 Buff[nThread].assign(m_numLogSteps, 0);
218#pragma omp for
219 for (int64_t i = 0; i < nHist; ++i) {
220 const auto loopThread = PARALLEL_THREAD_NUMBER;
222
223 // Get a const event list reference. eventInputWS->dataY() doesn't work.
224 const DataObjects::EventList &el = InputWorkspace->getSpectrum(i);
225 el.generateCountsHistogramPulseTime(dTRangeMin, dTRangeMax, Buff[loopThread], m_XRangeMin, m_XRangeMax);
226 if (this->buildVisWS()) {
227 this->histogramEvents(el, pVisWS_locks.get());
228 }
229
230 // Report progress
231 prog.report(name());
233 }
235// calculate final sums
236#pragma omp for
237 for (int64_t j = 0; j < m_numLogSteps; j++) {
238
239 for (int i = 0; i < nThreads; i++) {
240 countRate[j] += Buff[i][j];
241 }
242 // normalize if requested
243 if (!countNormalization.empty()) {
244 countRate[j] /= countNormalization[j];
245 }
246 }
247 if (!countNormalization.empty() && this->buildVisWS()) {
248#pragma omp for
249 for (int64_t j = 0; j < int64_t(m_visNorm.size()); j++) {
250 m_visWs->mutableY(j) /= m_visNorm[j];
251 }
252 }
253 }
254
255 // generate target log timing
256 std::vector<Types::Core::DateAndTime> times(m_numLogSteps);
257 double dt = (dTRangeMax - dTRangeMin) / static_cast<double>(m_numLogSteps);
258 auto t0 = m_TRangeMin.totalNanoseconds();
259 for (auto i = 0; i < m_numLogSteps; i++) {
260 times[i] = Types::Core::DateAndTime(t0 + static_cast<int64_t>((0.5 + double(i)) * dt));
261 }
262 // store calculated values within the target log.
263 targLog->replaceValues(times, countRate);
264}
270void CalculateCountRate::histogramEvents(const DataObjects::EventList &el, std::mutex *spectraLocks) {
271
272 if (el.empty())
273 return;
274
275 auto events = el.getEvents();
276 for (const Types::Event::TofEvent &ev : events) {
277 double pulsetime = static_cast<double>(ev.pulseTime().totalNanoseconds());
278 double tof = ev.tof();
279 if (pulsetime < m_visT0 || pulsetime >= m_visTmax)
280 continue;
281 if (tof < m_XRangeMin || tof >= m_XRangeMax)
282 continue;
283
284 auto n_spec = static_cast<size_t>((pulsetime - m_visT0) / m_visDT);
285 auto n_bin = static_cast<size_t>((tof - m_XRangeMin) / m_visDX);
286 (spectraLocks + n_spec)->lock();
287 auto &Y = m_visWs->mutableY(n_spec);
288 Y[n_bin]++;
289 (spectraLocks + n_spec)->unlock();
290 }
291}
292
296void CalculateCountRate::disableNormalization(const std::string &NormLogError) {
297 g_log.warning() << NormLogError << std::endl;
298 m_pNormalizationLog = nullptr;
299 m_normalizeResult = false;
300}
301/*Analyse input log parameters and logs, attached to the workspace and identify
302 * the parameters of the target log, including experiment time.
303 *
304 @param InputWorkspace -- input workspace to analyse logs
305 */
307
308 std::string NormLogName = getProperty("NormalizationLogName");
309 std::string TargetLog = getProperty("CountRateLogName");
310 if (NormLogName == TargetLog) {
311 throw std::invalid_argument("Target log name: " + TargetLog + " and normalization log name: " + NormLogName +
312 " can not be the same");
313 }
314
315 m_normalizeResult = getProperty("NormalizeTheRate");
316 bool useLogDeriv = getProperty("UseLogDerivative");
317 bool useLogAccuracy = getProperty("UseNormLogGranularity");
318
319 bool logPresent = InputWorkspace->run().hasProperty(NormLogName);
320 if (!logPresent) {
321 if (m_normalizeResult) {
322 this->disableNormalization("Normalization log '" + NormLogName +
323 "' values requested but the log is not attached to the "
324 "workspace. Normalization disabled");
325 }
326 if (useLogDeriv) {
327 g_log.warning() << "Normalization by log: '" << NormLogName
328 << "' -- log derivative requested but the source log is "
329 "not attached to "
330 "the workspace. Log derivative will not be used.\n";
331 useLogDeriv = false;
332 }
333 if (useLogAccuracy) {
334 g_log.warning() << "Using accuracy of the log: '" << NormLogName
335 << "' is requested but the log is not attached to the "
336 "workspace. Will use accuracy defined by "
337 "'NumTimeSteps' property value.\n";
338 useLogAccuracy = false;
339 }
340 } else {
341 m_pNormalizationLog = InputWorkspace->run().getTimeSeriesProperty<double>(NormLogName);
342 }
343
344 // Analyse properties interactions
345
346 // if property derivative is specified.
347 if (useLogDeriv) {
350 m_useLogDerivative = true;
351 }
352
354 if (m_normalizeResult) {
355 if (!useLogAccuracy) {
356 g_log.warning() << "Change of the counting log accuracy while "
357 "normalizing by log values is not implemented. Will "
358 "use log accuracy.\n";
359 useLogAccuracy = true;
360 }
361 } //---------------------------------------------------------------------
362 // find target log ranges and identify what normalization should be used
363
364 Types::Core::DateAndTime runTMin, runTMax;
365 InputWorkspace->getPulseTimeMinMax(runTMin, runTMax);
366 //
367 if (useLogAccuracy) { // extract log times located inside the run time
368 Types::Core::DateAndTime tLogMin, tLogMax;
369 if (m_useLogDerivative) { // derivative moves events to the bin centre,
370 // but we need initial range
371 auto pSource = InputWorkspace->run().getTimeSeriesProperty<double>(NormLogName);
372 tLogMin = pSource->firstTime();
373 tLogMax = pSource->lastTime();
374 } else {
375 tLogMin = m_pNormalizationLog->firstTime();
376 tLogMax = m_pNormalizationLog->lastTime();
377 }
378 //
379 if (tLogMin < runTMin || tLogMax > runTMax) {
380 if (tLogMin > runTMax || tLogMax < runTMin) { // log time is outside of the experiment time.
381 // Log normalization is impossible
382 this->disableNormalization("Normalization log " + m_pNormalizationLog->name() +
383 " time lies outside of the whole experiment time. "
384 "Log normalization impossible.");
385 useLogAccuracy = false;
386 } else {
387 if (!m_tmpLogHolder) {
388 m_tmpLogHolder = std::unique_ptr<Kernel::TimeSeriesProperty<double>>(m_pNormalizationLog->clone());
389 }
390 Kernel::TimeROI roi(runTMin, runTMax);
393 filteredLog->filterWith(roi);
394 m_pNormalizationLog = filteredLog;
395 } else {
397 filteredLog->filterWith(roi);
398 m_pNormalizationLog = filteredLog;
399 }
400
402 }
403 } else {
404 if (tLogMin > runTMin || tLogMax < runTMax) {
405 this->disableNormalization("Normalization log " + m_pNormalizationLog->name() +
406 " time does not cover the whole experiment time. "
407 "Log normalization impossible.");
408 useLogAccuracy = false;
409 }
410 }
411 }
412
413 if (useLogAccuracy) {
415 if (m_numLogSteps < 2) { // should not ever happen but...
416
417 this->disableNormalization("Number of points in the Normalization log " + m_pNormalizationLog->name() +
418 " smaller then 2. Can not normalize using this log.");
419 m_numLogSteps = getProperty("NumTimeSteps"); // Always > 2
420 useLogAccuracy = false;
421 }
422 } else {
423 m_numLogSteps = getProperty("NumTimeSteps");
424 }
425 // identify epsilon to use with current time
426 double t_epsilon = double(runTMax.totalNanoseconds()) * (1 + std::numeric_limits<double>::epsilon());
427 auto eps_increment = static_cast<int64_t>(t_epsilon - double(runTMax.totalNanoseconds()));
428
429 m_TRangeMin = runTMin - eps_increment;
430 if (useLogAccuracy) {
431 // Let's try to establish log step (it should be constant in real
432 // applications) and define
433 // binning in such a way, that each historgam bin accomodates
434 // single log value.
435 auto iTMax = runTMax.totalNanoseconds();
436 auto iTMin = m_TRangeMin.totalNanoseconds();
437 int64_t provDT = (iTMax - iTMin) / (m_numLogSteps - 1);
438 if (provDT < 1) { // something is fundamentally wrong. This can only happen
439 // if the log is very short and the distance between log
440 // boundaries is smaller than dt
441 this->disableNormalization("Time step of the log " + m_pNormalizationLog->name() +
442 " is not consistent with number of log steps. "
443 "Can not use this log normalization");
444 useLogAccuracy = false;
445 } else {
446 auto iTMax1 = iTMin + provDT * m_numLogSteps;
447 if (iTMax1 <= iTMax) { // == is possible
449 iTMax1 = iTMin + provDT * m_numLogSteps;
450 }
451 m_TRangeMax = Types::Core::DateAndTime(iTMax1);
452 }
453 }
454
455 if (!useLogAccuracy) {
456 // histogramming excludes rightmost events. Modify max limit to keep them
457 m_TRangeMax = runTMax + eps_increment; // Should be
458 // *(1+std::numeric_limits<double>::epsilon())
459 // but DateTime does not have multiplication
460 // operator
461 }
462}
463
464/* Retrieve and define data search ranges from input workspace parameters and
465 * algorithm properties
466 *
467 *@param InputWorkspace -- event workspace to process. Also retrieves algorithm
468 * properties, relevant to the workspace.
469 *@return -- the input workspace cropped according to XMin-XMax ranges in units,
470 * requested by the user
471 *
472 */
474
475 std::string RangeUnits = getProperty("RangeUnits");
476 auto axis = InputWorkspace->getAxis(0);
477 const auto unit = axis->unit();
478
480 if (unit->unitID() != RangeUnits) {
481 auto conv = createChildAlgorithm("ConvertUnits", 0, 1);
482 std::string wsName = InputWorkspace->getName();
483 if (wsName.empty()) {
484 wsName = "_CountRate_UnitsConverted";
485 } else {
486 wsName = "_" + wsName + "_converted";
487 }
488
489 conv->setProperty("InputWorkspace", InputWorkspace);
490 conv->setPropertyValue("OutputWorkspace", wsName);
491 std::string Emode = getProperty("Emode");
492 conv->setProperty("Emode", Emode);
493 conv->setProperty("Target", RangeUnits);
494
495 conv->setRethrows(true);
496 conv->execute();
497 wst = conv->getProperty("OutputWorkspace");
498
499 } else {
500 wst = InputWorkspace;
501 }
502 m_workingWS = std::dynamic_pointer_cast<DataObjects::EventWorkspace>(wst);
503 if (!m_workingWS) {
504 throw std::runtime_error("SetWSDataRanges:Can not retrieve EventWorkspace "
505 "after converting units");
506 }
507 // data ranges
508 m_XRangeMin = getProperty("XMin");
509 m_XRangeMax = getProperty("XMax");
510
511 if (m_XRangeMin == EMPTY_DBL() && m_XRangeMax == EMPTY_DBL()) {
512 m_rangeExplicit = false;
513 } else {
514 m_rangeExplicit = true;
515 }
516
517 double realMin, realMax;
518 m_workingWS->getEventXMinMax(realMin, realMax);
519 if (!m_rangeExplicit) { // The range is the whole workspace range
520 m_XRangeMin = realMin;
521 // include rightmost limit into the histogramming
522 m_XRangeMax = realMax * (1. + std::numeric_limits<double>::epsilon());
523 return;
524 }
525
526 if (m_XRangeMin == EMPTY_DBL()) {
527 m_XRangeMin = realMin;
528 }
529 if (m_XRangeMax == EMPTY_DBL()) {
530 // include rightmost limit into the histogramming
531 m_XRangeMax = realMax * (1. + std::numeric_limits<double>::epsilon());
532 }
533 if (m_XRangeMin < realMin) {
534 g_log.debug() << "Workspace constrain min range changed from: " << m_XRangeMin << " To: " << realMin << std::endl;
535 m_XRangeMin = realMin;
536 }
537 if (m_XRangeMax > realMax) {
538 g_log.debug() << "Workspace constrain max range changed from: " << m_XRangeMax << " To: " << realMax << std::endl;
539 m_XRangeMax = realMax * (1. + std::numeric_limits<double>::epsilon());
540 }
541 // check final ranges valid
542 if (m_XRangeMax < realMin || m_XRangeMin > realMax) {
543 throw std::invalid_argument(" Spurion data search range: [" + std::to_string(m_XRangeMin) + "," +
544 std::to_string(m_XRangeMin) + "] lies outside of the workspace's real data range: [" +
545 std::to_string(realMin) + "," + std::to_string(realMax) + "]");
546 }
547
548 if (m_XRangeMin > m_XRangeMax) {
549 throw std::invalid_argument(" Minimal spurion search data limit is bigger "
550 "than the maximal limit. ( Min: " +
552 }
553}
554
560 std::string visWSName = getProperty("VisualizationWs");
561 if (visWSName.empty()) {
562 m_visWs.reset();
563 m_doVis = false;
564 return;
565 }
566 m_doVis = true;
567
568 int numTBins = getProperty("NumTimeSteps");
569 if (this->normalizeCountRate()) {
570 if (numTBins > m_numLogSteps) {
571 g_log.information() << "Number of time step in normalized visualization "
572 "workspace exceeds the number of points in the "
573 "normalization log. This mode is not supported so "
574 "number of time steps decreased to be equal to "
575 "the number of normalization log points\n";
576 numTBins = m_numLogSteps;
577 }
578 }
579 int numXBins = getProperty("XResolution");
580 std::string RangeUnits = getProperty("RangeUnits");
581
582 m_visWs = create<Workspace2D>(numTBins, BinEdges(numXBins + 1));
583 m_visWs->setTitle(visWSName);
584
585 double Xmax = m_XRangeMax;
586 // a bit dodgy code. It can be generalized
587 if (std::isinf(Xmax)) {
588 const auto &Xbin = m_workingWS->x(0);
589 for (int64_t i = Xbin.size() - 1; i >= 0; --i) {
590 if (!std::isinf(Xbin[i])) {
591 Xmax = Xbin[i];
592 break;
593 }
594 }
595 if (std::isinf(Xmax)) {
596 g_log.warning() << "All X-range for visualization workspace is infinity. "
597 "Can not build visualization workspace in the units "
598 "requested\n";
599 m_visWs.reset();
600 m_doVis = false;
601 return;
602 }
603 }
604
605 // define X-axis in target units
606 double dX = (Xmax - m_XRangeMin) / numXBins;
607 std::vector<double> xx(numXBins);
608 for (int i = 0; i < numXBins; ++i) {
609 xx[i] = m_XRangeMin + (0.5 + static_cast<double>(i)) * dX;
610 }
611 auto ax0 = std::make_unique<API::NumericAxis>(xx);
612 ax0->setUnit(RangeUnits);
613 m_visWs->replaceAxis(0, std::move(ax0));
614
615 // define Y axis (in seconds);
616 double dt = (static_cast<double>(m_TRangeMax.totalNanoseconds() - m_TRangeMin.totalNanoseconds()) /
617 static_cast<double>(numTBins)) *
618 1.e-9;
619 xx.resize(numTBins);
620 for (int i = 0; i < numTBins; i++) {
621 xx[i] = (0.5 + static_cast<double>(i)) * dt;
622 }
623 auto ax1 = std::make_unique<API::NumericAxis>(xx);
624 auto labelY = std::dynamic_pointer_cast<Kernel::Units::Label>(Kernel::UnitFactory::Instance().create("Label"));
625 labelY->setLabel("sec");
626 ax1->unit() = labelY;
627 m_visWs->replaceAxis(1, std::move(ax1));
628
629 setProperty("VisualizationWs", m_visWs);
630
631 // define binning parameters used while calculating visualization
633 m_visDX = dX;
634 m_visT0 = static_cast<double>(m_TRangeMin.totalNanoseconds());
635 m_visTmax = static_cast<double>(m_TRangeMax.totalNanoseconds());
636 m_visDT = (m_visTmax - m_visT0) / static_cast<double>(numTBins);
637
638 if (this->normalizeCountRate()) {
639 m_visNorm.resize(numTBins);
641 }
642}
645
653
662void CalculateCountRate::buildVisWSNormalization(std::vector<double> &normalization) {
663 if (!m_pNormalizationLog) {
664 m_normalizeResult = false;
665 g_log.warning() << "CalculateCountRate::buildVisWSNormalization: No source "
666 "normalization log is found. Will not normalize "
667 "visualization workspace\n";
668 return;
669 }
670 // visualization workspace should be present and initialized at this stage:
671 const auto ax = dynamic_cast<const API::NumericAxis *>(m_visWs->getAxis(1));
672 if (!ax)
673 throw std::runtime_error("Can not retrieve Y-axis from visualization workspace");
674
675 normalization.assign(ax->length(), 0.);
676 // For more accurate logging (in a future, if necessary:)
677 // auto t_bins = ax->createBinBoundaries();
678 // double dt = t_bins[2] - t_bins[1]; // equal bins, first bin may be weird.
679 //
681}
682
683} // namespace Mantid::Algorithms
std::string name
Definition Run.cpp:60
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:538
#define PARALLEL_THREAD_NUMBER
#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_NUMBER_OF_THREADS
#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.
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.
Kernel::Logger & g_log
Definition Algorithm.h:422
Class to represent a numeric axis of a workspace.
Definition NumericAxis.h:29
Helper class for reporting progress from algorithms.
Definition Progress.h:25
A property class for workspaces.
In normal circumstances an instrument in event mode counts neutrons with constant steady rate which d...
void setSourceWSandXRanges(DataObjects::EventWorkspace_sptr &InputWorkspace)
void calcRateLog(DataObjects::EventWorkspace_sptr &InputWorkspace, Kernel::TimeSeriesProperty< double > *const targLog)
Process input workspace to calculate instrument counting rate as function of experiment time.
bool m_doVis
should algo generate visualization VS
void setOutLogParameters(const DataObjects::EventWorkspace_sptr &InputWorkspace)
void checkAndInitVisWorkspace()
Check if visualization workspace is necessary and initiate it if requested.
bool m_normalizeResult
pointer to the log used to normalize results or NULL if no such log present on input workspace.
bool buildVisWS() const
helper function to test if visualization workspace is requested
DataObjects::EventWorkspace_sptr m_workingWS
temporary workspace used to keep intermediate results
double m_XRangeMin
spurion search ranges (TOF or other units requested)
bool normalizeCountRate() const
Helper function: true if count rate should be normalized and false otherwise.
void disableNormalization(const std::string &NormLogError)
Disable normalization using normalization log.
Types::Core::DateAndTime m_TRangeMin
experiment time ranges:
DataObjects::Workspace2D_sptr m_visWs
shared pointer to the optional visualization workspace
Kernel::TimeSeriesProperty< double > const * m_pNormalizationLog
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
const std::string category() const override
Algorithm's category for identification.
bool m_rangeExplicit
specify if rate is calculated in selected frame interval (range defined) or all frame should be used
const std::string name() const override
Algorithms name for identification.
void init() override
Declare the algorithm's properties.
void histogramEvents(const DataObjects::EventList &el, std::mutex *spectraLocks)
histogram event list into visualization workspace
std::unique_ptr< Kernel::TimeSeriesProperty< double > > m_tmpLogHolder
void buildVisWSNormalization(std::vector< double > &normalization)
method to prepare normalization vector for the visualisation workspace using data from normalization ...
int m_numLogSteps
default number of points in the target log
int version() const override
Algorithm's version for identification.
bool useLogDerivative() const
Helper function to test if log derivative is used.
void exec() override
Execute the algorithm.
A class for holding :
Definition EventList.h:57
std::vector< Types::Event::TofEvent > & getEvents()
Return the list of TofEvents contained.
void generateCountsHistogramPulseTime(const double &xMin, const double &xMax, MantidVec &Y, const double TofMin=std::numeric_limits< double >::lowest(), const double TofMax=std::numeric_limits< double >::max()) const
With respect to PulseTime fill a histogram given equal histogram bins.
bool empty() const
Much like stl containers, returns true if there is nothing in the event list.
Templated class that defines a filtered time series but still gives access to the original data.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void setPropertyGroup(const std::string &name, const std::string &group)
Set the group for a given property.
void debug(const std::string &msg)
Logs at debug level.
Definition Logger.cpp:145
void warning(const std::string &msg)
Logs at warning level.
Definition Logger.cpp:117
void information(const std::string &msg)
Logs at information level.
Definition Logger.cpp:136
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.
The concrete, templated class for properties.
const std::string & name() const
Get the property's name.
Definition Property.cpp:61
TimeROI : Object that holds information about when the time measurement was active.
Definition TimeROI.h:18
A specialised Property class for holding a series of time-value pairs.
void replaceValues(const std::vector< Types::Core::DateAndTime > &times, const std::vector< TYPE > &values)
Replaces the time series with new values time series values.
TimeSeriesProperty< TYPE > * clone() const override
"Virtual" copy constructor
int size() const override
Returns the number of values at UNIQUE time intervals in the time series.
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.
void histogramData(const Types::Core::DateAndTime &tMin, const Types::Core::DateAndTime &tMax, std::vector< double > &counts) const
generate constant time-step histogram from the property values
Types::Core::DateAndTime lastTime() const
Returns the last time.
std::unique_ptr< TimeSeriesProperty< double > > getDerivative() const
Return time series property, containing time derivative of current property.
EventType
What kind of event list is being stored.
Definition IEventList.h:18
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Definition cow_ptr.h:172
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
Definition EmptyValues.h:42
STL namespace.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ InOut
Both an input & output workspace.
Definition Property.h:55
@ Input
An input workspace.
Definition Property.h:53
@ Output
An output workspace.
Definition Property.h:54