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