Mantid
Loading...
Searching...
No Matches
AlignAndFocusPowderSlim.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2024 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 +
7
10#include "MantidAPI/Axis.h"
13#include "MantidAPI/Run.h"
14#include "MantidAPI/Sample.h"
38#include "MantidKernel/Timer.h"
39#include "MantidKernel/Unit.h"
40#include "MantidKernel/V3D.h"
42#include "MantidNexus/H5Util.h"
43
44#include <H5Cpp.h>
45#include <cctype>
46#include <numbers>
47#include <ranges>
48#include <regex>
49#include <vector>
50
72
73namespace { // anonymous namespace
74
75const std::string LOG_CHARGE_NAME("proton_charge");
76
77const std::vector<std::string> binningModeNames{"Logarithmic", "Linear"};
78enum class BinningMode { LOGARITHMIC, LINEAR, enum_count };
80
81const std::vector<std::string> unitNames{"dSpacing", "TOF", "MomentumTransfer"};
82enum class BinUnit { DSPACE, TOF, Q, enum_count };
84
85const std::string ENTRY_TOP_LEVEL("entry");
86
87// TODO refactor this to use the actual grouping
88double getFocussedPostion(const detid_t detid, const std::vector<double> &difc_focus,
89 std::map<detid_t, size_t> &detIDToSpecNum) {
90 if (detIDToSpecNum.contains(detid)) {
91 return difc_focus[detIDToSpecNum[detid]];
92 } else {
93 return IGNORE_PIXEL;
94 }
95}
96
97std::vector<double> calculate_difc_focused(const double l1, const std::vector<double> &l2s,
98 const std::vector<double> &polars) {
99 constexpr double deg2rad = std::numbers::pi_v<double> / 180.;
100
101 std::vector<double> difc;
102
103 std::transform(l2s.cbegin(), l2s.cend(), polars.cbegin(), std::back_inserter(difc),
104 [l1, deg2rad](const auto &l2, const auto &polar) {
105 return 1. / Kernel::Units::tofToDSpacingFactor(l1, l2, deg2rad * polar, 0.);
106 });
107
108 return difc;
109}
110
111} // namespace
112
113// Register the algorithm into the AlgorithmFactory
114DECLARE_ALGORITHM(AlignAndFocusPowderSlim)
115
116//----------------------------------------------------------------------------------------------
117
118
119const std::string AlignAndFocusPowderSlim::name() const { return "AlignAndFocusPowderSlim"; }
120
122int AlignAndFocusPowderSlim::version() const { return 1; }
123
125const std::string AlignAndFocusPowderSlim::category() const { return "Workflow\\Diffraction"; }
126
128const std::string AlignAndFocusPowderSlim::summary() const {
129 return "Algorithm to focus powder diffraction data into a number of histograms according to a grouping "
130 "scheme defined in a CalFile.";
131}
132
133const std::vector<std::string> AlignAndFocusPowderSlim::seeAlso() const { return {"AlignAndFocusPowderFromFiles"}; }
134
135//----------------------------------------------------------------------------------------------
139 const std::vector<std::string> exts{".nxs.h5", ".nxs", "_event.nxs"};
140 // docs copied/modified from LoadEventNexus
141 declareProperty(std::make_unique<FileProperty>(PropertyNames::FILENAME, "", FileProperty::Load, exts),
142 "The name of the Event NeXus file to read, including its full or relative path. "
143 "The file name is typically of the form INST_####_event.nxs.");
146 "To only include events after the provided start time, in seconds (relative to the start of the run).");
147
150 "To only include events before the provided stop time, in seconds (relative to the start of the run).");
153 "Input workspace specifying \"splitters\", i.e. time intervals and targets for event filtering. "
154 "Currently only a single output workspace is supported.");
156 "Flag indicating whether in SplitterWorkspace the times are absolute or "
157 "relative. If true, they are relative to the run start time.");
160 "For development testing. Changes how the splitters are processed. If true then use ProcessBankSplitTask "
161 "otherwise loop over ProcessBankTask.");
163 "Find time-of-flight when neutron was at the sample position. This is only necessary for fast logs "
164 "(i.e. more frequent than proton on target pulse).");
167 "If true, events will be splitting using full time values (tof+pulsetime) rather than just pulsetime.");
168 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
169 mustBePositive->setLower(0);
171 "Filter bad pulses in the same way that :ref:`algm-FilterBadPulses` does.");
172 auto range = std::make_shared<BoundedValidator<double>>();
173 range->setBounds(0., 100.);
175 "The percentage of the average to use as the lower bound when filtering bad pulses.");
178 "A GroupingWorkspace giving the grouping info. If not provided then the grouping from the "
179 "calibration file will be used if provided, else a default grouping of one group per bank.");
180 const std::vector<std::string> cal_exts{".h5", ".hd5", ".hdf", ".cal"};
181 declareProperty(std::make_unique<FileProperty>(PropertyNames::CAL_FILE, "", FileProperty::OptionalLoad, cal_exts),
182 "The .cal file containing the position correction factors. Either this or OffsetsWorkspace needs to "
183 "be specified.");
184 const std::vector<std::string> grp_exts{".xml", ".h5", ".hd5", ".hdf", ".cal"};
185 declareProperty(std::make_unique<FileProperty>(PropertyNames::GROUP_FILE, "", FileProperty::OptionalLoad, grp_exts),
186 "An optional file containing grouping information. Overrides grouping from CalFileName. "
187 "Supported formats: XML (from SaveDetectorsGrouping) and HDF5/cal (from LoadDiffCal).");
188 auto mustBePosArr = std::make_shared<Kernel::ArrayBoundedValidator<double>>();
189 mustBePosArr->setLower(0.0);
190 declareProperty(std::make_unique<ArrayProperty<double>>(PropertyNames::X_MIN, std::vector<double>{0.1}, mustBePosArr),
191 "Minimum x-value for the output binning");
192 declareProperty(std::make_unique<ArrayProperty<double>>(PropertyNames::X_DELTA, std::vector<double>{0.0016}),
193 "Bin size for output data");
194 declareProperty(std::make_unique<ArrayProperty<double>>(PropertyNames::X_MAX, std::vector<double>{2.0}, mustBePosArr),
195 "Minimum x-value for the output binning");
197 "The units of the input X min, max and delta values. Output will always be TOF");
199 "Specify binning behavior ('Logarithmic')");
202 "If specified, only these logs will be loaded from the file. Setting this will automatically override the "
203 "default LogBlockList");
206 std::vector<std::string>{"Phase\\*", "Speed\\*", "BL\\*:Chop:\\*", "chopper\\*TDC"}),
207 "If specified, these logs will not be loaded from the file. Set as empty list ``[]`` to disable");
210 "An output workspace.");
211
212 // parameters for chunking options - consider removing these later
213 const std::string CHUNKING_PARAM_GROUP("Chunking-temporary");
214 auto positiveIntValidator = std::make_shared<Mantid::Kernel::BoundedValidator<int>>();
215 positiveIntValidator->setLower(1);
217 std::make_unique<PropertyWithValue<int>>(PropertyNames::READ_SIZE_FROM_DISK, 10000000, positiveIntValidator),
218 "Number of elements of time-of-flight or detector-id to read at a time. This is a maximum");
221 std::make_unique<PropertyWithValue<int>>(PropertyNames::EVENTS_PER_THREAD, 1000, positiveIntValidator),
222 "Number of events to read in a single thread. Higher means less threads are created.");
224
225 // load single bank
227 std::make_unique<PropertyWithValue<int>>(PropertyNames::BANK_NUMBER, EMPTY_INT(), positiveIntValidator),
228 "The bank for which to read data; if specified, others will be blank");
229
230 // parameters for focus position
231 // for L1, mandatory and must be positive
232 auto mandatoryDblValidator = std::make_shared<MandatoryValidator<double>>();
233 auto positiveDblValidator = std::make_shared<Mantid::Kernel::BoundedValidator<double>>();
234 positiveDblValidator->setLower(0);
235 auto l1Validator = std::make_shared<CompositeValidator>();
236 l1Validator->add(mandatoryDblValidator);
237 l1Validator->add(positiveDblValidator);
238 // for L2, 2theta, phi, mandatory arrays with positive valyes
239 auto mandatoryDblArrayValidator = std::make_shared<MandatoryValidator<std::vector<double>>>();
240 auto positionArrayValidator = std::make_shared<CompositeValidator>();
241 positionArrayValidator->add(mandatoryDblArrayValidator);
242 positionArrayValidator->add(mustBePosArr);
243 declareProperty(std::make_unique<PropertyWithValue<double>>(PropertyNames::L1, EMPTY_DBL(), l1Validator),
244 "The primary distance :math:`\\ell_1` from beam to sample");
246 std::make_unique<ArrayProperty<double>>(PropertyNames::L2, std::vector<double>{}, positionArrayValidator),
247 "The secondary distances :math:`\\ell_2` from sample to focus group");
249 std::make_unique<ArrayProperty<double>>(PropertyNames::POLARS, std::vector<double>{}, positionArrayValidator),
250 "The effective polar angle (:math:`2\\theta`) of each focus group");
252 std::make_unique<ArrayProperty<double>>(PropertyNames::AZIMUTHALS, std::vector<double>{}, mustBePosArr),
253 "The effective azimuthal angle :math:`\\phi` for each focus group");
254}
255
256std::map<std::string, std::string> AlignAndFocusPowderSlim::validateInputs() {
257 std::map<std::string, std::string> errors;
258
259 // make sure that data is read in larger chunks than the events processed in a single thread
260 const int disk_chunk = getProperty(PropertyNames::READ_SIZE_FROM_DISK);
261 const int grainsize_events = getProperty(PropertyNames::EVENTS_PER_THREAD);
262 if (disk_chunk < grainsize_events) {
263 const std::string msg(PropertyNames::READ_SIZE_FROM_DISK + " must be larger than " +
267 }
268
269 // only specify allow or block list for logs
270 std::vector<std::string> block_logs = getProperty(PropertyNames::BLOCK_LOGS);
271 if ((!isDefault(PropertyNames::ALLOW_LOGS)) && (!isDefault(PropertyNames::BLOCK_LOGS) && !block_logs.empty())) {
272 errors[PropertyNames::ALLOW_LOGS] = "Cannot specify both allow and block lists";
273 errors[PropertyNames::BLOCK_LOGS] = "Cannot specify both allow and block lists";
274 }
275
276 // the focus group position parameters must have same lengths
277 std::vector<double> l2s = getProperty(PropertyNames::L2);
278 const auto num_l2s = l2s.size();
279 std::vector<double> twoTheta = getProperty(PropertyNames::POLARS);
280 if (num_l2s != twoTheta.size()) {
281 errors[PropertyNames::L2] = strmakef("L2S has inconsistent length %zu", num_l2s);
282 errors[PropertyNames::POLARS] = strmakef("Polar has inconsistent length %zu", twoTheta.size());
283 }
284 // phi is optional, but if set must also have same size
285 std::vector<double> phi = getProperty(PropertyNames::AZIMUTHALS);
286 if (!phi.empty()) {
287 if (num_l2s != phi.size()) {
288 errors[PropertyNames::L2] = strmakef("L2S has inconsistent length %zu", num_l2s);
289 errors[PropertyNames::AZIMUTHALS] = strmakef("Azimuthal has inconsistent length %zu", phi.size());
290 ;
291 }
292 }
293
294 // validate binning information is consistent with each other and number of focus groups
295 const std::vector<double> xmins = getProperty(PropertyNames::X_MIN);
296 const std::vector<double> xmaxs = getProperty(PropertyNames::X_MAX);
297 const std::vector<double> deltas = getProperty(PropertyNames::X_DELTA);
298
299 const auto numMin = xmins.size();
300 const auto numMax = xmaxs.size();
301 const auto numDelta = deltas.size();
302
303 if (std::any_of(deltas.cbegin(), deltas.cend(), [](double d) { return !std::isfinite(d) || d == 0; }))
304 errors[PropertyNames::X_DELTA] = "All must be nonzero";
305 else if (!(numDelta == 1 || numDelta == num_l2s))
306 errors[PropertyNames::X_DELTA] = "Must have 1 or consistent number of values";
307
308 if (!(numMin == 1 || numMin == num_l2s))
309 errors[PropertyNames::X_MIN] = "Must have 1 or consistent number of values";
310 if (!(numMax == 1 || numMax == num_l2s))
311 errors[PropertyNames::X_MAX] = "Must have 1 or consistent number of values";
312 return errors;
313}
314
315//----------------------------------------------------------------------------------------------
319
320 const std::string filename = getPropertyValue(PropertyNames::FILENAME);
321 const Nexus::NexusDescriptor descriptor(filename);
322
323 std::vector<std::string> bankEntryNames;
324 std::vector<std::string> bankNames;
325 determineBanksToLoad(descriptor, bankEntryNames, bankNames);
326
327 const std::size_t num_banks_to_read = bankEntryNames.size();
328 g_log.debug() << "Total banks to read: " << num_banks_to_read << "\n";
329
330 H5::H5File h5file(filename, H5F_ACC_RDONLY, Nexus::H5Util::defaultFileAcc());
331
332 // These give the limits in each file as to which events we actually load (when filtering by time).
333 loadStart.resize(1, 0);
334 loadSize.resize(1, 0);
335
336 size_t num_hist;
337 std::map<size_t, std::set<detid_t>> grouping;
339
340 // Create the output workspace. Load the instrument, this is needed for LoadDiffCal but we cannot create the
341 // output workspace yet because we need grouping information from the cal file to know the correct number of
342 // spectra. We also need to load logs before instrument so we have the correct start time.
343 MatrixWorkspace_sptr wksp = std::make_shared<Workspace2D>();
344 try {
345 LoadEventNexus::loadEntryMetadata(filename, wksp, ENTRY_TOP_LEVEL);
346 } catch (std::exception &e) {
347 g_log.warning() << "Error while loading meta data: " << e.what() << '\n';
348 }
349
350 auto periodLog = std::make_unique<const TimeSeriesProperty<int>>("period_log"); // not used
351 const std::vector<std::string> &allow_logs = getProperty(PropertyNames::ALLOW_LOGS);
352 std::vector<std::string> block_logs = getProperty(PropertyNames::BLOCK_LOGS);
354 block_logs.clear();
355 g_log.information() << "User provided LogAllowList, default LogBlockList being ignored\n";
356 }
357 int nPeriods{1};
358 LoadEventNexus::runLoadNexusLogs<MatrixWorkspace_sptr>(filename, wksp, *this, false, nPeriods, periodLog, allow_logs,
359 block_logs);
360
361 LoadEventNexus::loadInstrument<MatrixWorkspace_sptr>(filename, wksp, ENTRY_TOP_LEVEL, this, &descriptor);
362
363 // load grouping from a separate file if provided (takes priority over grouping from CalFileName)
364 const std::string grp_filename = getPropertyValue(PropertyNames::GROUP_FILE);
365 if (!grp_filename.empty() && !groupingWS) {
366 groupingWS = this->loadGroupingFile(wksp, grp_filename);
367 }
368
369 // load calibration file if provided
370 const std::string cal_filename = getPropertyValue(PropertyNames::CAL_FILE);
371 ITableWorkspace_sptr calibrationWS;
372 if (!cal_filename.empty()) {
373 calibrationWS = this->loadCalFile(wksp, cal_filename, groupingWS);
374 }
375
376 if (groupingWS) {
377 const auto groupIds = groupingWS->getGroupIDs(false);
378 num_hist = groupIds.size();
379 g_log.information() << "Using grouping workspace with " << num_hist << " groups\n";
380 for (size_t outputindex = 0; outputindex < groupIds.size(); ++outputindex) {
381 const auto detids = groupingWS->getDetectorIDsOfGroup(groupIds[outputindex]);
382 grouping[outputindex] = std::set<detid_t>(detids.begin(), detids.end());
383 }
384 } else {
385 // if no grouping defined then everything goes to one spectrum
386 num_hist = 1;
387 }
388
389 this->progress(.0, "Create output workspace");
390 // initialize the workspace with correct number of histograms and bins
391 initializeOutputWorkspace(wksp, num_hist);
392
393 // TODO parameters should be input information
394 const double l1 = getProperty(PropertyNames::L1);
395 const std::vector<double> l2s = getProperty(PropertyNames::L2);
396 const std::vector<double> polars = getProperty(PropertyNames::POLARS); // two-theta
397 // set angle from positive x-axis; will be zero unless specified
398 std::vector<double> setPhi(l2s.size(), 0.0);
401 }
402 const std::vector<double> azimuthals(setPhi);
403 const std::vector<specnum_t> specids;
404 const auto difc_focused = calculate_difc_focused(l1, l2s, polars);
405
406 const auto timeSplitter = this->timeSplitterFromSplitterWorkspace(wksp->run().startTime());
407 const auto filterROI = this->getFilterROI(wksp);
408 // determine the pulse indices from the time and splitter workspace
409 this->progress(.05, "Determining pulse indices");
410
411 this->progress(.07, "Reading events");
412
413 // get detector ids for each bank
414 std::map<size_t, std::set<detid_t>> bank_detids;
415 for (size_t bankIndex = 0; bankIndex < num_banks_to_read; ++bankIndex) {
416 try {
417 bank_detids[bankIndex] = wksp->getInstrument()->getDetectorIDsInBank(bankNames.at(bankIndex));
418 } catch (std::exception &e) {
419 g_log.warning() << "Error getting detector IDs for " << bankNames.at(bankIndex) << ": " << e.what() << "\n";
420 }
421 }
422
423 // create map of detid to output spectrum number to be used in focusing
424 if (!grouping.empty()) {
425 for (const auto &group : grouping) {
426 for (const auto &detid : group.second) {
427 detIDToSpecNum[detid] = group.first;
428 }
429 }
430 } else {
431 // no grouping provided so everything goes in the 1 output spectrum
432 grouping[0] = std::set<detid_t>{};
433 for (const auto &[i, detids] : bank_detids) {
434 grouping[0].insert(detids.begin(), detids.end());
435 for (const auto &detid : detids) {
436 detIDToSpecNum[detid] = 0;
437 }
438 }
439 }
440
441 // create values for focusing time-of-flight
442 this->progress(.1, "Creating calibration constants");
443 if (calibrationWS) {
444 this->initCalibrationConstantsFromCalWS(difc_focused, calibrationWS);
445 } else {
446 this->initCalibrationConstants(wksp, difc_focused);
447 }
448
449 // calculate correction for tof of the neutron at the sample position
451 this->initScaleAtSample(wksp);
452 }
453
454 // set the instrument. Needs to happen after we get detector ids for each bank
455 this->progress(.15, "Set instrument geometry");
456 wksp = this->editInstrumentGeometry(wksp, l1, polars, specids, l2s, azimuthals);
457
458 // convert to TOF if not already
459 this->progress(.17, "Convert bins to TOF");
460 wksp = this->convertToTOF(wksp);
461
462 // create the bank calibration factory to share with all of the ProcessBank*Task objects
463 BankCalibrationFactory calibFactory(m_calibration, m_scale_at_sample, grouping, m_masked, bank_detids);
464
465 // threaded processing of the banks
466 const int DISK_CHUNK = getProperty(PropertyNames::READ_SIZE_FROM_DISK);
467 const int GRAINSIZE_EVENTS = getProperty(PropertyNames::EVENTS_PER_THREAD);
468 g_log.debug() << (DISK_CHUNK / GRAINSIZE_EVENTS) << " threads per chunk\n";
469
470 // get pulse times from frequency log on workspace. We use this in several places.
471 const auto frequency_log = dynamic_cast<const TimeSeriesProperty<double> *>(wksp->run().getProperty("frequency"));
472 if (!frequency_log) {
473 throw std::runtime_error("Frequency log not found in workspace run");
474 }
475 m_pulse_times = std::make_shared<std::vector<Mantid::Types::Core::DateAndTime>>(frequency_log->timesAsVector());
476
477 if (timeSplitter.empty()) {
478 // create the nexus loader for handling combined calls to hdf5
479
481 const auto pulse_indices = this->determinePulseIndices(filterROI);
482 auto loader = std::make_shared<NexusLoader>(is_time_filtered, pulse_indices);
483
484 auto progress = std::make_shared<API::Progress>(this, .17, .9, num_banks_to_read);
485 ProcessBankTask task(bankEntryNames, h5file, loader, processingData, calibFactory, static_cast<size_t>(DISK_CHUNK),
486 static_cast<size_t>(GRAINSIZE_EVENTS), progress);
487 // generate threads only if appropriate
488 if (num_banks_to_read > 1) {
489 tbb::parallel_for(tbb::blocked_range<size_t>(0, num_banks_to_read), task);
490 } else {
491 task(tbb::blocked_range<size_t>(0, 1));
492 }
493
494 // close the file so child algorithms can do their thing
495 h5file.close();
496
497 // copy data from processingData to wksp
498 storeSpectraProcessingData(processingData, wksp);
499
500 // update the run TimeROI and remove log data outside the time ROI
501 wksp->mutableRun().setTimeROI(filterROI);
502 wksp->mutableRun().removeDataOutsideTimeROI();
503
504 setProperty(PropertyNames::OUTPUT_WKSP, std::move(wksp));
505 } else {
506 std::string ws_basename = this->getPropertyValue(PropertyNames::OUTPUT_WKSP);
507 std::vector<std::string> wsNames;
508 std::vector<int> workspaceIndices;
509 std::vector<MatrixWorkspace_sptr> workspaces;
510 std::vector<SpectraProcessingData> processingDatas;
511 for (const int &splitter_target : timeSplitter.outputWorkspaceIndices()) {
512 std::string ws_name = ws_basename + "_" + timeSplitter.getWorkspaceIndexName(splitter_target);
513 wsNames.push_back(std::move(ws_name));
514 workspaceIndices.push_back(splitter_target);
515 workspaces.emplace_back(wksp->clone());
516 processingDatas.push_back(initializeSpectraProcessingData(workspaces.back()));
517 }
518
519 auto progress = std::make_shared<API::Progress>(this, .17, .9, num_banks_to_read * workspaceIndices.size());
521 g_log.information() << "Using ProcessBankSplitFullTimeTask for splitter processing\n";
522
523 // Get the combined time ROI for all targets so we only load necessary events.
524 // Need to offset the start time to account for tof's greater than pulsetime. 66.6ms is 4 pulses.
525 auto combined_time_roi = timeSplitter.combinedTimeROI(PULSETIME_OFFSET);
526 if (!filterROI.useAll()) {
527 combined_time_roi.update_intersection(filterROI);
528 }
529
530 // create the nexus loader for handling combined calls to hdf5
531 const auto pulse_indices = this->determinePulseIndices(combined_time_roi);
532 auto loader = std::make_shared<NexusLoader>(is_time_filtered, pulse_indices);
533
534 const auto &splitterMap = timeSplitter.getSplittersMap();
535
536 ProcessBankSplitFullTimeTask task(bankEntryNames, h5file, loader, workspaceIndices, processingDatas, calibFactory,
537 static_cast<size_t>(DISK_CHUNK), static_cast<size_t>(GRAINSIZE_EVENTS),
538 splitterMap, m_pulse_times, progress);
539
540 // generate threads only if appropriate
541 if (num_banks_to_read > 1) {
542 tbb::parallel_for(tbb::blocked_range<size_t>(0, num_banks_to_read), task);
543 } else {
544 task(tbb::blocked_range<size_t>(0, 1));
545 }
546
548 g_log.information() << "Using ProcessBankSplitTask for splitter processing\n";
549 // determine the pulse indices from the time and splitter workspace
550 const auto target_to_pulse_indices = this->determinePulseIndicesTargets(filterROI, timeSplitter);
551 // create the nexus loader for handling combined calls to hdf5
552 std::vector<PulseROI> pulse_indices; // intentionally empty to get around loader needing const reference
553 auto loader = std::make_shared<NexusLoader>(is_time_filtered, pulse_indices, target_to_pulse_indices);
554
555 ProcessBankSplitTask task(bankEntryNames, h5file, loader, workspaceIndices, processingDatas, calibFactory,
556 static_cast<size_t>(DISK_CHUNK), static_cast<size_t>(GRAINSIZE_EVENTS), progress);
557 // generate threads only if appropriate
558 if (num_banks_to_read > 1) {
559 tbb::parallel_for(tbb::blocked_range<size_t>(0, num_banks_to_read), task);
560 } else {
561 task(tbb::blocked_range<size_t>(0, 1));
562 }
563 } else {
564 g_log.information() << "Using ProcessBankTask for splitter processing\n";
565 // loop over the targets in the splitter workspace, each target gets its own output workspace
566 tbb::parallel_for(
567 tbb::blocked_range<size_t>(0, workspaceIndices.size()),
568 [&](const tbb::blocked_range<size_t> &target_indices) {
569 for (size_t target_index = target_indices.begin(); target_index != target_indices.end(); ++target_index) {
570 const int splitter_target = workspaceIndices[target_index];
571
572 auto splitter_roi = timeSplitter.getTimeROI(splitter_target);
573 // copy the roi so we can modify it just for this target
574 auto target_roi = filterROI;
575 if (target_roi.useAll())
576 target_roi = std::move(splitter_roi); // use the splitter ROI if no time filtering is specified
577 else if (!splitter_roi.useAll())
578 target_roi.update_intersection(splitter_roi); // otherwise intersect with the splitter ROI
579
580 // clone wksp for this target
581 MatrixWorkspace_sptr target_wksp = workspaces[target_index];
582
583 const auto pulse_indices = this->determinePulseIndices(target_roi);
584 auto loader = std::make_shared<NexusLoader>(is_time_filtered, pulse_indices);
585
586 ProcessBankTask task(bankEntryNames, h5file, loader, processingDatas[target_index], calibFactory,
587 static_cast<size_t>(DISK_CHUNK), static_cast<size_t>(GRAINSIZE_EVENTS), progress);
588 // generate threads only if appropriate
589 if (num_banks_to_read > 1) {
590 tbb::parallel_for(tbb::blocked_range<size_t>(0, num_banks_to_read), task);
591 } else {
592 task(tbb::blocked_range<size_t>(0, 1));
593 }
594 }
595 });
596 }
597
598 // close the file so child algorithms can do their thing
599 h5file.close();
600
601 // add the workspaces to the ADS
602 for (size_t idx = 0; idx < workspaceIndices.size(); ++idx) {
603 // copy data from processingData to wksp
604 storeSpectraProcessingData(processingDatas[idx], workspaces[idx]);
605
606 // create the target time ROI combining the splitter and filter ROIs
607 auto target_roi = timeSplitter.getTimeROI(workspaceIndices[idx]);
608 if (target_roi.useAll())
609 target_roi = filterROI; // use the splitter ROI if no time filtering is specified
610 else if (!filterROI.useAll())
611 target_roi.update_intersection(filterROI); // otherwise intersect with the splitter ROI
612
613 // update the run TimeROI and remove log data outside the time ROI
614 workspaces[idx]->mutableRun().setTimeROI(target_roi);
615 workspaces[idx]->mutableRun().removeDataOutsideTimeROI();
616 AnalysisDataService::Instance().addOrReplace(wsNames[idx], workspaces[idx]);
617 }
618
619 // group the workspaces
620 auto groupws = createChildAlgorithm("GroupWorkspaces", 0.95, 1.00, true);
621 groupws->setAlwaysStoreInADS(true);
622 groupws->setProperty("InputWorkspaces", wsNames);
623 groupws->setProperty("OutputWorkspace", ws_basename);
624 groupws->execute();
625
626 if (!groupws->isExecuted()) {
627 throw std::runtime_error("Failed to group output workspaces");
628 }
629
630 API::Workspace_sptr outputWorkspace = AnalysisDataService::Instance().retrieveWS<API::Workspace>(ws_basename);
631
632 setProperty(PropertyNames::OUTPUT_WKSP, outputWorkspace);
633 }
634}
635
636void AlignAndFocusPowderSlim::determineBanksToLoad(const Nexus::NexusDescriptor &descriptor,
637 std::vector<std::string> &bankEntryNames,
638 std::vector<std::string> &bankNames) {
639 // Now we want to go through all the bankN_event entries
640
641 std::set<std::string> const classEntries = descriptor.allAddressesOfType("NXevent_data");
642 if (classEntries.empty()) {
643 throw std::runtime_error("No NXevent_data entries found in file");
644 }
645
646 const int bankNum = getProperty(PropertyNames::BANK_NUMBER);
647
648 const std::regex classRegex("(/entry/)([^/]*)");
649 std::smatch groups;
650 for (const std::string &classEntry : classEntries) {
651 if (std::regex_match(classEntry, groups, classRegex)) {
652 const std::string entry_name(groups[2].str());
653 if (classEntry.ends_with("bank_error_events")) {
654 // do nothing
655 } else if (classEntry.ends_with("bank_unmapped_events")) {
656 // do nothing
657 } else {
658 auto underscore_pos = entry_name.find_first_of('_');
659 const auto bankName = entry_name.substr(0, underscore_pos);
660 if (bankNum != EMPTY_INT()) {
661 if (bankName != ("bank" + std::to_string(bankNum))) {
662 continue; // skip this bank
663 }
664 }
665 bankEntryNames.push_back(entry_name);
666 bankNames.push_back(bankName);
667 }
668 }
669 }
670}
671
672void AlignAndFocusPowderSlim::initializeOutputWorkspace(const MatrixWorkspace_sptr &wksp, size_t num_hist) {
673 // set up the output workspace binning
674 const BINMODE binmode = getPropertyValue(PropertyNames::BINMODE);
675 const bool linearBins = bool(binmode == BinningMode::LINEAR);
676 const std::string binUnits = getPropertyValue(PropertyNames::BIN_UNITS);
677 std::vector<double> x_delta = getProperty(PropertyNames::X_DELTA);
678 std::vector<double> x_min = getProperty(PropertyNames::X_MIN);
679 std::vector<double> x_max = getProperty(PropertyNames::X_MAX);
680 const bool raggedBins = (x_delta.size() != 1 || x_min.size() != 1 || x_max.size() != 1);
681
682 constexpr bool resize_xnew{true};
683 constexpr bool full_bins_only{false};
684
685 // always use the first histogram x-values for initialization
686 double const binWidth = linearBins ? x_delta[0] : -1. * std::abs(x_delta[0]);
687 std::vector<double> xAxisTmp;
688 Kernel::VectorHelper::createAxisFromRebinParams({x_min[0], binWidth, x_max[0]}, xAxisTmp, resize_xnew,
689 full_bins_only);
690 HistogramData::BinEdges XValues(std::move(xAxisTmp));
691 wksp->initialize(num_hist, HistogramData::Histogram(XValues, HistogramData::Counts(XValues.size() - 1, 0.0)));
692
693 if (raggedBins) {
694 // if ragged bins, we need to resize the x-values for each histogram after the first one
695 if (x_delta.size() == 1)
696 x_delta.resize(num_hist, x_delta[0]);
697 if (x_min.size() == 1)
698 x_min.resize(num_hist, x_min[0]);
699 if (x_max.size() == 1)
700 x_max.resize(num_hist, x_max[0]);
701
702 for (size_t i = 1; i < num_hist; ++i) {
703 double const raggedBinWidth = linearBins ? x_delta[i] : -1. * std::abs(x_delta[i]);
704 std::vector<double> const params{x_min[i], raggedBinWidth, x_max[i]};
705 std::vector<double> xtmpragged;
706 Kernel::VectorHelper::createAxisFromRebinParams(params, xtmpragged, resize_xnew, full_bins_only);
707 HistogramData::BinEdges XValues_new(std::move(xtmpragged));
708 wksp->setHistogram(i, HistogramData::Histogram(XValues_new, HistogramData::Counts(XValues_new.size() - 1, 0.0)));
709 }
710 }
711
712 wksp->getAxis(0)->setUnit(binUnits);
713 wksp->setYUnit("Counts");
714}
715
717AlignAndFocusPowderSlim::initializeSpectraProcessingData(const API::MatrixWorkspace_sptr &outputWS) {
718 SpectraProcessingData processingData;
719 const size_t numSpectra = outputWS->getNumberHistograms();
720 for (size_t i = 0; i < numSpectra; ++i) {
721 const auto &spectrum = outputWS->getSpectrum(i);
722 processingData.binedges.emplace_back(&spectrum.readX());
723 processingData.counts.emplace_back(spectrum.dataY().size());
724 }
725 return processingData;
726}
727
728void AlignAndFocusPowderSlim::storeSpectraProcessingData(const SpectraProcessingData &processingData,
729 const API::MatrixWorkspace_sptr &outputWS) {
730 const size_t numSpectra = outputWS->getNumberHistograms();
731 for (size_t i = 0; i < numSpectra; ++i) {
732 auto &spectrum = outputWS->getSpectrum(i);
733 auto &y_values = spectrum.dataY();
734 std::transform(
735 processingData.counts[i].cbegin(), processingData.counts[i].cend(), y_values.begin(),
736 [](const std::atomic_uint32_t &val) { return static_cast<double>(val.load(std::memory_order_relaxed)); });
737 auto &e_values = spectrum.dataE();
738 std::transform(processingData.counts[i].cbegin(), processingData.counts[i].cend(), e_values.begin(),
739 [](const std::atomic_uint32_t &val) {
740 return std::sqrt(static_cast<double>(val.load(std::memory_order_relaxed)));
741 });
742 }
743}
744
745void AlignAndFocusPowderSlim::initCalibrationConstants(API::MatrixWorkspace_sptr &wksp,
746 const std::vector<double> &difc_focus) {
747 const auto detInfo = wksp->detectorInfo();
748
749 for (auto iter = detInfo.cbegin(); iter != detInfo.cend(); ++iter) {
750 if (!iter->isMonitor()) {
751 const auto difc_focussed = getFocussedPostion(static_cast<detid_t>(iter->detid()), difc_focus, detIDToSpecNum);
752 if (difc_focussed == IGNORE_PIXEL)
753 m_calibration.emplace(static_cast<detid_t>(iter->detid()), IGNORE_PIXEL);
754 else
755 m_calibration.emplace(static_cast<detid_t>(iter->detid()),
756 difc_focussed / detInfo.difcUncalibrated(iter->index()));
757 }
758 }
759}
760
761void AlignAndFocusPowderSlim::initCalibrationConstantsFromCalWS(const std::vector<double> &difc_focus,
762 const ITableWorkspace_sptr calibrationWS) {
763 for (size_t row = 0; row < calibrationWS->rowCount(); ++row) {
764 const detid_t detid = calibrationWS->cell<int>(row, 0);
765 const double detc = calibrationWS->cell<double>(row, 1);
766 const auto difc_focussed = getFocussedPostion(detid, difc_focus, detIDToSpecNum);
767 if (difc_focussed == IGNORE_PIXEL)
768 m_calibration.emplace(detid, IGNORE_PIXEL);
769 else
770 m_calibration.emplace(detid, difc_focussed / detc);
771 }
772}
773
774const ITableWorkspace_sptr AlignAndFocusPowderSlim::loadCalFile(const API::Workspace_sptr &inputWS,
775 const std::string &filename,
776 GroupingWorkspace_sptr &groupingWS) {
777 const bool load_grouping = !groupingWS;
778
779 auto alg = createChildAlgorithm("LoadDiffCal");
780 alg->setPropertyValue("Filename", filename);
781 if (filename.ends_with(".cal")) {
782 alg->setProperty("InputWorkspace", inputWS);
783 } else {
784 // intentionally do not supply the input workspace because h5 version can work without
785 g_log.debug("Not supplying instrument information to LoadDifCal");
786 }
787 alg->setProperty<bool>("MakeCalWorkspace", true);
788 alg->setProperty<bool>("MakeGroupingWorkspace", load_grouping);
789 alg->setProperty<bool>("MakeMaskWorkspace", true);
790 alg->setPropertyValue("WorkspaceName", "temp");
791 alg->executeAsChildAlg();
792
793 if (load_grouping) {
794 g_log.debug() << "Loading grouping workspace from calibration file\n";
795 groupingWS = alg->getProperty("OutputGroupingWorkspace");
796 }
797
798 const ITableWorkspace_sptr calibrationWS = alg->getProperty("OutputCalWorkspace");
799
800 const MaskWorkspace_sptr maskWS = alg->getProperty("OutputMaskWorkspace");
801 m_masked = maskWS->getMaskedDetectors();
802 g_log.debug() << "Masked detectors: " << m_masked.size() << '\n';
803
804 return calibrationWS;
805}
806
811GroupingWorkspace_sptr AlignAndFocusPowderSlim::loadGroupingFile(const API::MatrixWorkspace_sptr &wksp,
812 const std::string &filename) {
813 g_log.debug() << "Loading grouping from file: " << filename << '\n';
814
815 // case-insensitive extension check
816 std::string lowerFilename = filename;
817 std::transform(lowerFilename.begin(), lowerFilename.end(), lowerFilename.begin(),
818 [](unsigned char c) { return std::tolower(c); });
819
820 GroupingWorkspace_sptr groupingWS;
821 if (lowerFilename.ends_with(".xml")) {
822 // XML grouping files can carry their own instrument/date metadata. Do not
823 // supply InputWorkspace here because LoadDetectorsGroupingFile treats that
824 // as an override; without it, the child algorithm will use the instrument
825 // information embedded in the XML file.
826 auto alg = createChildAlgorithm("LoadDetectorsGroupingFile");
827 alg->setPropertyValue("InputFile", filename);
828 alg->executeAsChildAlg();
829 groupingWS = alg->getProperty("OutputWorkspace");
830 } else {
831 // HDF5 or .cal grouping file -- use LoadDiffCal as the Filename (cal file) parameter
832 auto alg = createChildAlgorithm("LoadDiffCal");
833 alg->setPropertyValue("Filename", filename);
834 if (lowerFilename.ends_with(".cal")) {
835 // .cal format requires an instrument to be provided
836 alg->setProperty("InputWorkspace", std::dynamic_pointer_cast<API::Workspace>(wksp));
837 }
838 alg->setProperty<bool>("MakeCalWorkspace", false);
839 alg->setProperty<bool>("MakeGroupingWorkspace", true);
840 alg->setProperty<bool>("MakeMaskWorkspace", false);
841 alg->setPropertyValue("WorkspaceName", "slim_grp");
842 alg->executeAsChildAlg();
843 groupingWS = alg->getProperty("OutputGroupingWorkspace");
844 }
845 return groupingWS;
846}
847
852void AlignAndFocusPowderSlim::initScaleAtSample(const API::MatrixWorkspace_sptr &wksp) {
853 // detector information for all of the L2
854 const auto detInfo = wksp->detectorInfo();
855 // cache a single L1 value
856 const double L1 = detInfo.l1();
857
858 if (this->getProperty(PropertyNames::CORRECTION_TO_SAMPLE)) {
859 // calculate scale factors for each detector
860 for (auto iter = detInfo.cbegin(); iter != detInfo.cend(); ++iter) {
861 if (!iter->isMonitor()) {
862 const double path_correction = L1 / (L1 + iter->l2()) * 1000.0;
863 m_scale_at_sample.emplace(static_cast<detid_t>(iter->detid()), path_correction);
864 }
865 }
866 } else {
867 // set all scale factors to 1.0
868 for (auto iter = detInfo.cbegin(); iter != detInfo.cend(); ++iter) {
869 if (!iter->isMonitor()) {
870 m_scale_at_sample.emplace(static_cast<detid_t>(iter->detid()), 1000.0);
871 }
872 }
873 }
874}
875
876API::MatrixWorkspace_sptr AlignAndFocusPowderSlim::editInstrumentGeometry(
877 API::MatrixWorkspace_sptr &wksp, const double l1, const std::vector<double> &polars,
878 const std::vector<specnum_t> &specids, const std::vector<double> &l2s, const std::vector<double> &azimuthals) {
879 API::IAlgorithm_sptr editAlg = createChildAlgorithm("EditInstrumentGeometry");
880 editAlg->setLoggingOffset(1);
881 editAlg->setProperty("Workspace", wksp);
882 if (l1 > 0.)
883 editAlg->setProperty("PrimaryFlightPath", l1);
884 if (!polars.empty())
885 editAlg->setProperty("Polar", polars);
886 if (!specids.empty())
887 editAlg->setProperty("SpectrumIDs", specids);
888 if (!l2s.empty())
889 editAlg->setProperty("L2", l2s);
890 if (!azimuthals.empty())
891 editAlg->setProperty("Azimuthal", azimuthals);
892 editAlg->executeAsChildAlg();
893
894 wksp = editAlg->getProperty("Workspace");
895
896 return wksp;
897}
898
899API::MatrixWorkspace_sptr AlignAndFocusPowderSlim::convertToTOF(API::MatrixWorkspace_sptr &wksp) {
900 if (wksp->getAxis(0)->unit()->unitID() == "TOF") {
901 // already in TOF, no need to convert
902 return wksp;
903 }
904
905 API::IAlgorithm_sptr convertUnits = createChildAlgorithm("ConvertUnits");
906 convertUnits->setProperty("InputWorkspace", wksp);
907 convertUnits->setPropertyValue("Target", "TOF");
908 convertUnits->executeAsChildAlg();
909 wksp = convertUnits->getProperty("OutputWorkspace");
910
911 return wksp;
912}
913
921Kernel::TimeROI AlignAndFocusPowderSlim::getFilterROI(const API::MatrixWorkspace_sptr &wksp) {
922 Kernel::TimeROI roi;
923 const auto startOfRun = wksp->run().startTime();
924
925 // filter by time
926 double filter_time_start_sec = getProperty(PropertyNames::FILTER_TIMESTART);
927 double filter_time_stop_sec = getProperty(PropertyNames::FILTER_TIMESTOP);
928 if (filter_time_start_sec != EMPTY_DBL() || filter_time_stop_sec != EMPTY_DBL()) {
929 this->progress(.15, "Creating time filtering");
930 g_log.information() << "Filtering pulses from " << filter_time_start_sec << " to " << filter_time_stop_sec << "s\n";
931
932 try {
933 roi.addROI(startOfRun + (filter_time_start_sec == EMPTY_DBL() ? 0.0 : filter_time_start_sec),
934 startOfRun + filter_time_stop_sec); // start and stop times in seconds
935 } catch (const std::runtime_error &e) {
936 throw std::invalid_argument("Invalid time range for filtering: " + std::string(e.what()));
937 }
938 }
939
940 // filter bad pulses
941 if (getProperty(PropertyNames::FILTER_BAD_PULSES)) {
942 this->progress(.16, "Filtering bad pulses");
943
944 // get limits from proton_charge
945 const auto [min_pcharge, max_pcharge, mean] =
946 wksp->run().getBadPulseRange(LOG_CHARGE_NAME, getProperty(PropertyNames::FILTER_BAD_PULSES_LOWER_CUTOFF));
947 g_log.information() << "Filtering bad pulses; pcharge outside of " << min_pcharge << " to " << max_pcharge << '\n';
948
949 const auto run_start = wksp->getFirstPulseTime();
950 const auto run_stop = wksp->getLastPulseTime();
951
952 const auto log = dynamic_cast<const TimeSeriesProperty<double> *>(wksp->run().getLogData(LOG_CHARGE_NAME));
953 if (log) {
954 // need to have centre=true for proton_charge
955 roi = log->makeFilterByValue(min_pcharge, max_pcharge, true, Mantid::Kernel::TimeInterval(run_start, run_stop),
956 0.0, true, &roi);
957 }
958 }
959 return roi;
960}
961
968std::vector<PulseROI> AlignAndFocusPowderSlim::determinePulseIndices(const TimeROI &filterROI) {
969
970 std::vector<PulseROI> pulse_indices;
971 if (filterROI.useAll()) {
972 pulse_indices.emplace_back(0, std::numeric_limits<size_t>::max());
973 } else {
974 is_time_filtered = true;
975 pulse_indices = filterROI.calculate_indices(*m_pulse_times);
976 if (pulse_indices.empty())
977 throw std::invalid_argument("No valid pulse time indices found for filtering");
978 }
979
980 return pulse_indices;
981}
982
991std::vector<std::pair<int, PulseROI>>
992AlignAndFocusPowderSlim::determinePulseIndicesTargets(const TimeROI &filterROI, const TimeSplitter &timeSplitter) {
993 std::vector<PulseROI> pulse_indices;
994 if (filterROI.useAll()) {
995 pulse_indices.emplace_back(0, std::numeric_limits<size_t>::max());
996 } else {
997 pulse_indices = filterROI.calculate_indices(*m_pulse_times);
998 if (pulse_indices.empty())
999 throw std::invalid_argument("No valid pulse time indices found for filtering");
1000 }
1001
1002 const auto target_to_pulse_indices = timeSplitter.calculate_target_indices(*m_pulse_times);
1003
1004 // calculate intersection of target pulse indices and time filter pulse indices (removes pulses outside filterROI)
1005 std::vector<std::pair<int, PulseROI>> intersected_target_pulse_indices;
1006 auto pulse_it = pulse_indices.cbegin();
1007 for (const auto &target_pair : target_to_pulse_indices) {
1008 // move pulse_it to the first pulse that could overlap
1009 while (pulse_it != pulse_indices.cend() && pulse_it->second <= target_pair.second.first) {
1010 ++pulse_it;
1011 }
1012 // check for overlaps
1013 auto check_it = pulse_it;
1014 while (check_it != pulse_indices.cend() && check_it->first < target_pair.second.second) {
1015 // there is an overlap
1016 size_t start_index = std::max(check_it->first, target_pair.second.first);
1017 size_t stop_index = std::min(check_it->second, target_pair.second.second);
1018 if (start_index < stop_index) {
1019 intersected_target_pulse_indices.emplace_back(target_pair.first, PulseROI(start_index, stop_index));
1020 }
1021 ++check_it;
1022 }
1023 }
1024
1025 return intersected_target_pulse_indices;
1026}
1027
1029AlignAndFocusPowderSlim::timeSplitterFromSplitterWorkspace(const Types::Core::DateAndTime &filterStartTime) {
1030 API::Workspace_sptr tempws = this->getProperty(PropertyNames::SPLITTER_WS);
1031 DataObjects::SplittersWorkspace_sptr splittersWorkspace =
1032 std::dynamic_pointer_cast<DataObjects::SplittersWorkspace>(tempws);
1033 DataObjects::TableWorkspace_sptr splitterTableWorkspace =
1034 std::dynamic_pointer_cast<DataObjects::TableWorkspace>(tempws);
1035 API::MatrixWorkspace_sptr matrixSplitterWS = std::dynamic_pointer_cast<API::MatrixWorkspace>(tempws);
1036
1037 if (!splittersWorkspace && !splitterTableWorkspace && !matrixSplitterWS)
1038 return {};
1039
1040 const bool isSplittersRelativeTime = this->getProperty(PropertyNames::SPLITTER_RELATIVE);
1041
1042 TimeSplitter time_splitter;
1043 if (splittersWorkspace) {
1044 time_splitter = TimeSplitter{splittersWorkspace};
1045 } else if (splitterTableWorkspace) {
1046 time_splitter =
1047 TimeSplitter(splitterTableWorkspace, isSplittersRelativeTime ? filterStartTime : DateAndTime::GPS_EPOCH);
1048 } else {
1049 time_splitter = TimeSplitter(matrixSplitterWS, isSplittersRelativeTime ? filterStartTime : DateAndTime::GPS_EPOCH);
1050 }
1051
1052 return time_splitter;
1053}
1054
1055} // namespace Mantid::DataHandling::AlignAndFocusPowderSlim
std::string name
Definition Run.cpp:60
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:542
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.
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:423
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
bool isDefault(const std::string &name) const
A specialized class for dealing with file properties.
@ OptionalLoad
to specify a file to read but the file doesn't have to exist
@ Load
allowed here which will be passed to the algorithm
A property class for workspaces.
Base Workspace Abstract Class.
Definition Workspace.h:29
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
DataObjects::GroupingWorkspace_sptr loadGroupingFile(const API::MatrixWorkspace_sptr &wksp, const std::string &filename)
Load a grouping workspace from an explicit grouping file.
std::vector< std::pair< size_t, size_t > > determinePulseIndices(const Kernel::TimeROI &filterROI)
Determine the pulse indices for a given workspace and time ROI.
std::map< std::string, std::string > validateInputs() override
Perform validation of ALL the input properties of the algorithm.
SpectraProcessingData initializeSpectraProcessingData(const API::MatrixWorkspace_sptr &outputWS)
std::vector< int64_t > loadStart
Index to load start at in the file.
std::shared_ptr< std::vector< Types::Core::DateAndTime > > m_pulse_times
void storeSpectraProcessingData(const SpectraProcessingData &processingData, const API::MatrixWorkspace_sptr &outputWS)
DataObjects::TimeSplitter timeSplitterFromSplitterWorkspace(const Types::Core::DateAndTime &)
void determineBanksToLoad(const Mantid::Nexus::NexusDescriptor &descriptor, std::vector< std::string > &bankEntryNames, std::vector< std::string > &bankNames)
std::map< detid_t, double > m_scale_at_sample
Multiplicative 0<value<1 to move neutron TOF at sample.
void initScaleAtSample(const API::MatrixWorkspace_sptr &wksp)
For fast logs, calculate the sample position correction.
const std::string category() const override
Algorithm's category for identification.
std::vector< std::pair< int, std::pair< size_t, size_t > > > determinePulseIndicesTargets(const Kernel::TimeROI &filterROI, const DataObjects::TimeSplitter &timeSplitter)
Determine the pulse indices for a given workspace, time ROI, and time splitter.
API::MatrixWorkspace_sptr editInstrumentGeometry(API::MatrixWorkspace_sptr &wksp, const double l1, const std::vector< double > &polars, const std::vector< specnum_t > &specids, const std::vector< double > &l2s, const std::vector< double > &azimuthals)
int version() const override
Algorithm's version for identification.
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm....
void initializeOutputWorkspace(const API::MatrixWorkspace_sptr &wksp, size_t num_hist)
void initCalibrationConstantsFromCalWS(const std::vector< double > &difc_focus, const API::ITableWorkspace_sptr calibrationWS)
const API::ITableWorkspace_sptr loadCalFile(const API::Workspace_sptr &inputWS, const std::string &filename, DataObjects::GroupingWorkspace_sptr &groupingWS)
Kernel::TimeROI getFilterROI(const API::MatrixWorkspace_sptr &wksp)
Create a TimeROI based on the filtering properties set in the algorithm.
API::MatrixWorkspace_sptr convertToTOF(API::MatrixWorkspace_sptr &wksp)
void initCalibrationConstants(API::MatrixWorkspace_sptr &wksp, const std::vector< double > &difc_focus)
static void loadEntryMetadata(const std::string &nexusfilename, T WS, const std::string &entry_name)
Load the run number and other meta data from the given bank.
std::vector< std::pair< int, std::pair< size_t, size_t > > > calculate_target_indices(const std::vector< DateAndTime > &times) const
Given a list of times, calculate the corresponding indices in the TimeSplitter.
Concrete workspace implementation.
Definition Workspace2D.h:29
Kernel/ArrayBoundedValidator.h.
Support for a property that holds an array of values.
BoundedValidator is a validator that requires the values to be between upper or lower bounds,...
A concrete property based on user options of a finite list of strings.
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.
The concrete, templated class for properties.
Represents a time interval.
Definition DateAndTime.h:25
TimeROI : Object that holds information about when the time measurement was active.
Definition TimeROI.h:18
std::vector< std::pair< size_t, size_t > > calculate_indices(const std::vector< Types::Core::DateAndTime > &times) const
Definition TimeROI.cpp:346
void addROI(const std::string &startTime, const std::string &stopTime)
Definition TimeROI.cpp:76
bool useAll() const
TimeROI selects all time to be used.
Definition TimeROI.cpp:693
A specialised Property class for holding a series of time-value pairs.
std::set< std::string > allAddressesOfType(const std::string &type) const
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Mantid::Kernel::SingletonHolder< AnalysisDataServiceImpl > AnalysisDataService
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
const std::string GROUPING_WS("GroupingWorkspace")
const std::string FILTER_TIMESTART("FilterByTimeStart")
const std::string FILTER_BAD_PULSES_LOWER_CUTOFF("BadPulsesLowerCutoff")
const std::string PROCESS_BANK_SPLIT_TASK("ProcessBankSplitTask")
const std::string CORRECTION_TO_SAMPLE("CorrectionToSample")
const std::string FILTER_TIMESTOP("FilterByTimeStop")
const std::string SPLITTER_WS("SplitterWorkspace")
const std::string EVENTS_PER_THREAD("EventsPerThread")
const std::string FILTER_BAD_PULSES("FilterBadPulses")
const std::string READ_SIZE_FROM_DISK("ReadSizeFromDisk")
std::shared_ptr< SplittersWorkspace > SplittersWorkspace_sptr
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
std::shared_ptr< GroupingWorkspace > GroupingWorkspace_sptr
shared pointer to the GroupingWorkspace class
std::shared_ptr< MaskWorkspace > MaskWorkspace_sptr
shared pointer to the MaskWorkspace class
constexpr double deg2rad
Defines units/enum for Crystal work.
Definition AngleUnits.h:20
MANTID_KERNEL_DLL std::string strmakef(char const *const fmt,...)
This is the constructor that std::string needed to have.
Definition Strings.cpp:1200
std::size_t MANTID_KERNEL_DLL createAxisFromRebinParams(const std::vector< double > &params, 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.
MANTID_NEXUS_DLL H5::FileAccPropList defaultFileAcc()
Default file access is H5F_CLOSE_STRONG.
Definition H5Util.cpp:119
const std::string BINMODE("BinningMode")
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
Definition EmptyValues.h:24
int32_t detid_t
Typedef for a detector ID.
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)
std::vector< std::vector< std::atomic_uint32_t > > counts
Describes the direction (within an algorithm) of a Property.
Definition Property.h:50
@ Input
An input workspace.
Definition Property.h:53
@ Output
An output workspace.
Definition Property.h:54