37using namespace Kernel;
45const std::string INPUT_WKSP(
"InputWorkspace");
46const std::string OUTPUT_WKSP(
"OutputWorkspace");
47const std::string UNFOCUS_WKSP(
"UnfocussedWorkspace");
48const std::string CAL_FILE(
"CalFileName");
49const std::string GROUP_FILE(
"GroupFilename");
50const std::string GROUP_WKSP(
"GroupingWorkspace");
51const std::string CAL_WKSP(
"CalibrationWorkspace");
52const std::string OFFSET_WKSP(
"OffsetsWorkspace");
53const std::string MASK_WKSP(
"MaskWorkspace");
54const std::string MASK_TABLE(
"MaskBinTable");
55const std::string BINNING(
"Params");
56const std::string RESAMPLEX(
"ResampleX");
57const std::string BIN_IN_D(
"Dspacing");
58const std::string D_MINS(
"DMin");
59const std::string D_MAXS(
"DMax");
60const std::string RAGGED_DELTA(
"DeltaRagged");
61const std::string TOF_MIN(
"TMin");
62const std::string TOF_MAX(
"TMax");
63const std::string WL_MIN(
"CropWavelengthMin");
64const std::string WL_MAX(
"CropWavelengthMax");
65const std::string PRESERVE_EVENTS(
"PreserveEvents");
66const std::string REMOVE_PROMPT_PULSE(
"RemovePromptPulseWidth");
67const std::string RESONANCE_UNITS(
"ResonanceFilterUnits");
68const std::string RESONANCE_LOWER_LIMITS(
"ResonanceFilterLowerLimits");
69const std::string RESONANCE_UPPER_LIMITS(
"ResonanceFilterUpperLimits");
70const std::string COMPRESS_TOF_TOL(
"CompressTolerance");
71const std::string COMPRESS_WALL_TOL(
"CompressWallClockTolerance");
72const std::string COMPRESS_WALL_START(
"CompressStartTime");
73const std::string COMPRESS_MODE(
"CompressBinningMode");
74const std::string L1(
"PrimaryFlightPath");
75const std::string SPEC_IDS(
"SpectrumIDs");
76const std::string L2(
"L2");
77const std::string POLAR(
"Polar");
78const std::string AZIMUTHAL(
"Azimuthal");
79const std::string PM_NAME(
"ReductionProperties");
80const std::string LORENTZ(
"LorentzCorrection");
81const std::string UNWRAP_REF(
"UnwrapRef");
82const std::string LOWRES_REF(
"LowResRef");
83const std::string LOWRES_SPEC_OFF(
"LowResSpectrumOffset");
87 if (
const auto eventWksp = std::dynamic_pointer_cast<const EventWorkspace>(wksp)) {
88 eventWksp->getEventXMinMax(tmin, tmax);
90 wksp->getXMinMax(tmin, tmax);
94const std::vector<std::string> binningModeNames{
"Default",
"Linear",
"Logarithmic"};
108 "The input workspace");
111 "The result of diffraction focussing of InputWorkspace");
114 "Treated data in d-spacing before focussing (optional). This will likely "
122 std::vector<std::string>{
".h5",
".hd5",
".hdf",
".cal"}),
123 "The name of the calibration file with offset, masking, and "
126 std::vector<std::string>{
".xml",
".cal"}),
127 "Overrides grouping from CalFileName");
130 "Optional: A GroupingWorkspace giving the grouping info.");
134 "Optional: A Workspace containing the calibration information. Either "
135 "this or CalibrationFile needs to be specified.");
138 "Optional: An OffsetsWorkspace giving the detector calibration values.");
141 "Optional: A workspace giving which detectors are masked.");
144 "Optional: A workspace giving pixels and bins to mask.");
147 "A comma separated list of first bin boundary, width, last bin boundary. "
149 "this can be followed by a comma and more widths and last boundary "
151 "Negative width values indicate logarithmic binning.");
152 declareProperty(PropertyNames::RESAMPLEX, 0,
153 "Number of bins in x-axis. Non-zero value "
154 "overrides \"Params\" property. Negative "
155 "value means logarithmic binning.");
156 setPropertySettings(PropertyNames::BINNING,
157 std::make_unique<EnabledWhenProperty>(PropertyNames::RESAMPLEX,
IS_DEFAULT));
158 declareProperty(PropertyNames::BIN_IN_D,
true,
"Bin in Dspace. (True is Dspace; False is TOF)");
160 "Minimum for Dspace axis. (Default 0.) ");
161 mapPropertyName(PropertyNames::D_MINS,
"d_min");
163 "Maximum for Dspace axis. (Default 0.) ");
164 mapPropertyName(PropertyNames::D_MAXS,
"d_max");
165 declareProperty(std::make_unique<
ArrayProperty<double>>(PropertyNames::RAGGED_DELTA),
"Step parameter for rebin");
166 mapPropertyName(PropertyNames::RAGGED_DELTA,
"delta");
167 declareProperty(PropertyNames::TOF_MIN,
EMPTY_DBL(),
"Minimum for TOF axis. Defaults to 0. ");
168 mapPropertyName(PropertyNames::TOF_MIN,
"tof_min");
169 declareProperty(PropertyNames::TOF_MAX,
EMPTY_DBL(),
"Maximum for TOF or dspace axis. Defaults to 0. ");
170 mapPropertyName(PropertyNames::TOF_MAX,
"tof_max");
171 declareProperty(PropertyNames::PRESERVE_EVENTS,
true,
172 "If the InputWorkspace is an "
173 "EventWorkspace, this will preserve "
174 "the full event list (warning: this "
175 "will use much more memory!).");
176 declareProperty(PropertyNames::REMOVE_PROMPT_PULSE, 0.,
177 "Width of events (in "
178 "microseconds) near the prompt "
179 "pulse to remove. 0 disables");
180 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
181 mustBePositive->setLower(0.0);
183 std::vector<std::string> allowedResonanceUnits({
"Energy",
"Wavelength"});
184 declareProperty(PropertyNames::RESONANCE_UNITS, allowedResonanceUnits.back(),
185 std::make_shared<StringListValidator>(allowedResonanceUnits),
186 "Units for resonances to be filtered in. "
187 "The data will be converted to these units temporarily to filter.");
189 "Minimum values to filter absorption resonance. This must have same number of values as "
190 "ResonanceFilterUpperLimits. Default behavior is to not filter.");
192 "Maximum values to filter absorption resonance. This must have same number of values as "
193 "ResonanceFilterLowerLimits. Default behavior is to not filter.");
196 "Compress events (in microseconds) within this tolerance. (Default 1e-5). If negative then do "
197 "logorithmic compression.");
200 "The tolerance (in seconds) on the wall-clock time for comparison. Unset "
201 "means compressing all wall-clock times together disabling pulsetime "
203 auto dateValidator = std::make_shared<DateTimeValidator>();
204 dateValidator->allowEmpty(
true);
205 declareProperty(PropertyNames::COMPRESS_WALL_START,
"", dateValidator,
206 "An ISO formatted date/time string specifying the timestamp for "
207 "starting filtering. Ignored if WallClockTolerance is not specified. "
208 "Default is start of run",
210 declareProperty(PropertyNames::COMPRESS_MODE, binningModeNames[
size_t(BinningMode::DEFAULT)],
211 std::make_shared<Mantid::Kernel::StringListValidator>(binningModeNames),
212 "Optional. Binning behavior can be specified in the usual way through sign of tolerance "
213 "('Default'); or can be set to one of the allowed binning modes. ");
214 declareProperty(PropertyNames::LORENTZ,
false,
215 "Multiply each spectrum by "
216 "sin(theta) where theta is "
217 "half of the Bragg angle");
218 declareProperty(PropertyNames::UNWRAP_REF, 0.,
"This property is deprecated (since v6.13).");
219 declareProperty(PropertyNames::LOWRES_REF, 0.,
"Reference DIFC for resolution removal. Zero skips the correction");
220 declareProperty(
"CropWavelengthMin", 0.,
"Crop the data at this minimum wavelength. Overrides LowResRef.");
221 mapPropertyName(PropertyNames::WL_MIN,
"wavelength_min");
222 declareProperty(
"CropWavelengthMax",
EMPTY_DBL(),
223 "Crop the data at this maximum wavelength. Forces use of "
224 "CropWavelengthMin.");
225 mapPropertyName(PropertyNames::WL_MAX,
"wavelength_max");
226 declareProperty(PropertyNames::L1, -1.0,
"If positive, focus positions are changed. (Default -1) ");
228 "Optional: Spectrum Nos (note that it is not detector ID or "
229 "workspace indices).");
231 "Optional: Secondary flight (L2) paths for each detector");
233 "Optional: Polar angles (two thetas) for detectors");
235 "Azimuthal angles (out-of-plain) for detectors");
237 declareProperty(PropertyNames::LOWRES_SPEC_OFF, -1,
238 "Offset on spectrum No of low resolution spectra from high "
240 "If negative, then all the low resolution TOF will not be "
241 "processed. Otherwise, low resolution TOF "
242 "will be stored in an additional set of spectra. "
243 "If offset is equal to 0, then the low resolution will have "
244 "same spectrum Nos as the normal ones. "
245 "Otherwise, the low resolution spectra will have spectrum "
246 "IDs offset from normal ones. ");
247 declareProperty(PropertyNames::PM_NAME,
"__powdereduction",
Direction::Input);
251 std::map<std::string, std::string> result;
253 if (!isDefault(PropertyNames::UNFOCUS_WKSP)) {
256 result[PropertyNames::UNFOCUS_WKSP] =
"Cannot be the same as OutputWorkspace";
260 if ((!isDefault(PropertyNames::RAGGED_DELTA)) && (!isDefault(PropertyNames::RESAMPLEX))) {
261 result[PropertyNames::RAGGED_DELTA] =
"Cannot specify with " + PropertyNames::RESAMPLEX;
262 result[PropertyNames::RESAMPLEX] =
"Cannot specify with " + PropertyNames::RAGGED_DELTA;
266 auto inputEW = std::dynamic_pointer_cast<EventWorkspace>(
m_inputW);
267 if (inputEW && inputEW->getNumberEvents() <= 0)
269 "Please plot the pCharge-time to identify suitable range for "
279 for (
size_t i = 0; i < NUM_WINDOWS; ++i) {
284 const std::string msg =
"Lower limits must be less than upper limits";
285 result[PropertyNames::RESONANCE_LOWER_LIMITS] = msg;
286 result[PropertyNames::RESONANCE_UPPER_LIMITS] = msg;
289 result[PropertyNames::RESONANCE_LOWER_LIMITS] =
290 "Must have same number of values as " + PropertyNames::RESONANCE_UPPER_LIMITS;
291 result[PropertyNames::RESONANCE_UPPER_LIMITS] =
292 "Must have same number of values as " + PropertyNames::RESONANCE_LOWER_LIMITS;
296 if (!isDefault(PropertyNames::UNWRAP_REF)) {
297 g_log.
error(
"AlignAndFocusPowder property UnwrapRef is deprecated since 2025-03-24.");
308template <
typename NumT>
315 if (orig.size() == numVal) {
316 out.
reg.assign(orig.begin(), orig.end());
317 out.
low.assign(orig.begin(), orig.end());
318 }
else if (orig.size() == 2 * numVal) {
319 out.
reg.assign(orig.begin(), orig.begin() + numVal);
320 out.
low.assign(orig.begin() + numVal, orig.begin());
322 std::stringstream msg;
323 msg <<
"Input number of " << label <<
" ids is not equal to "
324 <<
"the number of histograms or empty (" << orig.size() <<
" != 0 or " << numVal <<
" or " << (2 * numVal)
326 throw std::runtime_error(msg.str());
385 const bool applyLorentz =
getProperty(PropertyNames::LORENTZ);
394 double compressEventsTolerance =
getProperty(PropertyNames::COMPRESS_TOF_TOL);
395 const double wallClockTolerance =
getProperty(PropertyNames::COMPRESS_WALL_TOL);
397 if (mode == BinningMode::LINEAR)
398 compressEventsTolerance = std::fabs(compressEventsTolerance);
399 else if (mode == BinningMode::LOGARITHMIC)
400 compressEventsTolerance = -1. * std::fabs(compressEventsTolerance);
412 if (
m_params.size() == 1 && (!isEmpty(dmin)) && (!isEmpty(dmax))) {
413 if (dmin > 0. && dmax > dmin) {
422 g_log.
warning() <<
"something is wrong with dmin (" << dmin <<
") and dmax (" << dmax
423 <<
"). They are being ignored.\n";
437 <<
"). They are being ignored.\n";
455 int lowresoffset =
getProperty(PropertyNames::LOWRES_SPEC_OFF);
456 if (lowresoffset < 0) {
467 if (
auto inputEW = std::dynamic_pointer_cast<EventWorkspace>(
m_inputW)) {
472 m_outputW = std::dynamic_pointer_cast<MatrixWorkspace>(outputEW);
482 if (
auto inputEW = std::dynamic_pointer_cast<EventWorkspace>(
m_inputW)) {
484 m_lowResEW = std::dynamic_pointer_cast<EventWorkspace>(
491 throw std::runtime_error(
"Input workspace is not EventWorkspace. It is not supported now.");
496 m_progress = std::make_unique<Progress>(
this, 0., 1., 21);
499 g_log.
information() <<
"running MaskDetectors started at " << Types::Core::DateAndTime::getCurrentTime() <<
"\n";
504 maskDetAlg->setProperty(
"Workspace", outputw);
506 maskDetAlg->setProperty(
"MaskedWorkspace", mksws);
507 maskDetAlg->executeAsChildAlg();
508 outputw = maskDetAlg->getProperty(
"Workspace");
510 m_outputW = std::dynamic_pointer_cast<MatrixWorkspace>(outputw);
519 if (((!isEmpty(
xmin)) && (
xmin >= 0.)) || ((!isEmpty(
xmax)) && (
xmax > 0.))) {
523 cropAlg->setProperty(
"InputWorkspace",
m_outputW);
524 cropAlg->setProperty(
"OutputWorkspace",
m_outputW);
525 bool setxmin =
false;
526 if ((
xmin >= 0.) && (
xmin > tofmin)) {
527 cropAlg->setProperty(
"Xmin",
xmin);
531 bool setxmax =
false;
532 if ((
xmax > 0.) && (
xmax < tofmax)) {
533 cropAlg->setProperty(
"Xmax",
xmax);
538 if (setxmin || setxmax) {
540 << Types::Core::DateAndTime::getCurrentTime() <<
"\n";
541 cropAlg->executeAsChildAlg();
542 m_outputW = cropAlg->getProperty(
"OutputWorkspace");
548 const double removePromptPulseWidth =
getProperty(PropertyNames::REMOVE_PROMPT_PULSE);
549 if (removePromptPulseWidth > 0.) {
550 bool removePromptPulse(
false);
551 if (
auto outputEW = std::dynamic_pointer_cast<EventWorkspace>(
m_outputW)) {
552 removePromptPulse = (outputEW->getNumberEvents() > 0);
554 if (removePromptPulse) {
555 g_log.
information() <<
"running RemovePromptPulse(Width=" << removePromptPulseWidth <<
") started at "
556 << Types::Core::DateAndTime::getCurrentTime() <<
"\n";
558 filterPAlg->setProperty(
"InputWorkspace",
m_outputW);
559 filterPAlg->setProperty(
"OutputWorkspace",
m_outputW);
560 filterPAlg->setProperty(
"Width", removePromptPulseWidth);
564 filterPAlg->setProperty(
"TMin", tofmin);
565 filterPAlg->setProperty(
"TMax", tofmax);
567 filterPAlg->executeAsChildAlg();
568 m_outputW = filterPAlg->getProperty(
"OutputWorkspace");
575 if (maskBinTableWS) {
576 g_log.
information() <<
"running MaskBinsFromTable started at " << Types::Core::DateAndTime::getCurrentTime()
579 alg->setProperty(
"InputWorkspace",
m_outputW);
580 alg->setProperty(
"OutputWorkspace",
m_outputW);
581 alg->setProperty(
"MaskingInformation", maskBinTableWS);
582 alg->executeAsChildAlg();
583 m_outputW = alg->getProperty(
"OutputWorkspace");
599 << Types::Core::DateAndTime::getCurrentTime() <<
"\n";
602 applyDiffCalAlg->setProperty(
"InstrumentWorkspace", outputw);
604 applyDiffCalAlg->executeAsChildAlg();
606 outputw = applyDiffCalAlg->getProperty(
"InstrumentWorkspace");
607 m_outputW = std::dynamic_pointer_cast<MatrixWorkspace>(outputw);
625 applyDiffCalAlg->setProperty(
"InstrumentWorkspace", outputw);
626 applyDiffCalAlg->setProperty(
"ClearCalibration",
true);
627 applyDiffCalAlg->executeAsChildAlg();
629 outputw = applyDiffCalAlg->getProperty(
"InstrumentWorkspace");
630 m_outputW = std::dynamic_pointer_cast<MatrixWorkspace>(outputw);
642 g_log.
information() <<
"Applying Lorentz correction started at " << Types::Core::DateAndTime::getCurrentTime()
646 alg->setProperty(
"InputWorkspace",
m_outputW);
647 alg->setProperty(
"OutputWorkspace",
m_outputW);
648 alg->setPropertyValue(
"Type",
"PowderTOF");
649 alg->executeAsChildAlg();
650 m_outputW = alg->getProperty(
"OutputWorkspace");
660 if (
const auto ews = std::dynamic_pointer_cast<EventWorkspace>(
m_outputW))
661 g_log.
information() <<
"Number of events = " << ews->getNumberEvents() <<
".\n";
668 g_log.
information() <<
") started at " << Types::Core::DateAndTime::getCurrentTime() <<
"\n";
671 removeAlg->setProperty(
"InputWorkspace",
m_outputW);
672 removeAlg->setProperty(
"OutputWorkspace",
m_outputW);
673 removeAlg->setProperty(
"XMin",
minwl);
674 removeAlg->setProperty(
"XMax",
maxwl);
675 removeAlg->executeAsChildAlg();
676 m_outputW = removeAlg->getProperty(
"OutputWorkspace");
677 if (
const auto ews = std::dynamic_pointer_cast<EventWorkspace>(
m_outputW))
678 g_log.
information() <<
"Number of events = " << ews->getNumberEvents() <<
".\n";
687 << Types::Core::DateAndTime::getCurrentTime() <<
"\n";
688 if (
const auto ews = std::dynamic_pointer_cast<EventWorkspace>(
m_outputW))
689 g_log.
information() <<
"Number of events = " << ews->getNumberEvents() <<
".\n";
692 removeAlg->setProperty(
"InputWorkspace",
m_outputW);
693 removeAlg->setProperty(
"OutputWorkspace",
m_outputW);
694 removeAlg->setProperty(
"ReferenceDIFC",
DIFCref);
695 removeAlg->setProperty(
"K", 3.22);
697 removeAlg->setProperty(
"Tmin",
tmin);
699 removeAlg->setProperty(
"LowResTOFWorkspace",
m_lowResW);
701 removeAlg->executeAsChildAlg();
702 m_outputW = removeAlg->getProperty(
"OutputWorkspace");
704 m_lowResW = removeAlg->getProperty(
"LowResTOFWorkspace");
708 if (
const auto ews = std::dynamic_pointer_cast<EventWorkspace>(
m_outputW)) {
709 const size_t numhighevents = ews->getNumberEvents();
712 const size_t numlowevents = lowes->getNumberEvents();
713 g_log.
information() <<
"Number of high TOF events = " << numhighevents <<
"; "
714 <<
"Number of low TOF events = " << numlowevents <<
".\n";
736 if (!isDefault(
"UnfocussedWorkspace")) {
738 setProperty(
"UnfocussedWorkspace", std::move(wkspCopy));
772 size_t numreg =
m_outputW->getNumberHistograms();
787 }
catch (std::runtime_error &e) {
813 setProperty(
"OutputWorkspace",
m_outputW);
820 const std::vector<double> &polars,
821 const std::vector<specnum_t> &specids,
822 const std::vector<double> &l2s,
823 const std::vector<double> &phis) {
824 g_log.
information() <<
"running EditInstrumentGeometry started at " << Types::Core::DateAndTime::getCurrentTime()
828 editAlg->setProperty(
"Workspace", ws);
830 editAlg->setProperty(
"PrimaryFlightPath",
m_l1);
832 editAlg->setProperty(
"Polar", polars);
834 editAlg->setProperty(
"SpectrumIDs",
specids);
836 editAlg->setProperty(
"L2",
l2s);
838 editAlg->setProperty(
"Azimuthal",
phis);
839 editAlg->executeAsChildAlg();
841 ws = editAlg->getProperty(
"Workspace");
859 g_log.
information() <<
"running DiffractionFocussing(PreserveEvents=" << preserveEvents <<
") started at "
860 << Types::Core::DateAndTime::getCurrentTime() <<
"\n";
863 focusAlg->setProperty(
"InputWorkspace", ws);
864 focusAlg->setProperty(
"OutputWorkspace", ws);
865 focusAlg->setProperty(
"GroupingWorkspace",
m_groupWS);
866 focusAlg->setProperty(
"PreserveEvents", preserveEvents);
867 focusAlg->executeAsChildAlg();
868 ws = focusAlg->getProperty(
"OutputWorkspace");
883 focusAlg->setProperty(
"InputWorkspace", ws);
884 focusAlg->setProperty(
"OutputWorkspace", ws);
885 focusAlg->setProperty(
"GroupingWorkspace",
m_groupWS);
887 focusAlg->setProperty(
"DMin",
m_dmins);
888 focusAlg->setProperty(
"DMax",
m_dmaxs);
895 g_log.
information() <<
") started at " << Types::Core::DateAndTime::getCurrentTime() <<
"\n";
897 focusAlg->executeAsChildAlg();
898 ws = focusAlg->getProperty(
"OutputWorkspace");
906 const std::string &target) {
907 g_log.
information() <<
"running ConvertUnits(Target=" << target <<
") started at "
908 << Types::Core::DateAndTime::getCurrentTime() <<
"\n";
911 convert2Alg->setProperty(
"InputWorkspace", matrixws);
912 convert2Alg->setProperty(
"OutputWorkspace", matrixws);
913 convert2Alg->setProperty(
"Target", target);
914 convert2Alg->executeAsChildAlg();
916 matrixws = convert2Alg->getProperty(
"OutputWorkspace");
923 const std::string PREVIOUS_UNITS(matrixws->getAxis(0)->unit()->unitID());
932 for (
size_t i = 0; i < NUM_WINDOWS; ++i) {
934 <<
") started at " << Types::Core::DateAndTime::getCurrentTime() <<
"\n";
935 maskBinsAlg->setProperty(
"InputWorkspace", matrixws);
936 maskBinsAlg->setProperty(
"OutputWorkspace", matrixws);
939 maskBinsAlg->executeAsChildAlg();
941 matrixws = maskBinsAlg->getProperty(
"OutputWorkspace");
959 <<
", dMin(" <<
m_dmins.size() <<
"), dmax(" <<
m_dmaxs.size() <<
")) started at "
960 << Types::Core::DateAndTime::getCurrentTime() <<
"\n";
962 alg->setProperty(
"InputWorkspace", matrixws);
963 alg->setProperty(
"OutputWorkspace", matrixws);
965 size_t numHist =
m_outputW->getNumberHistograms();
967 alg->setProperty(
"XMin",
m_dmins);
968 alg->setProperty(
"XMax",
m_dmaxs);
971 <<
"number of workspace indices. Ignoring the parameters.\n";
976 alg->executeAsChildAlg();
977 matrixws = alg->getProperty(
"OutputWorkspace");
983 g_log.
information() <<
") started at " << Types::Core::DateAndTime::getCurrentTime() <<
"\n";
989 rebin3Alg->setProperty(
"InputWorkspace", matrixws);
990 rebin3Alg->setProperty(
"OutputWorkspace", matrixws);
991 rebin3Alg->setProperty(
"Params",
m_params);
992 rebin3Alg->executeAsChildAlg();
993 matrixws = rebin3Alg->getProperty(
"OutputWorkspace");
1003 bool print_xmin =
false;
1004 bool print_xmax =
false;
1011 alg->setProperty(
"XMin",
m_dmins);
1015 alg->setProperty(
"XMax",
m_dmaxs);
1021 alg->setProperty(
"XMin", std::vector<double>(1,
tmin));
1026 alg->setProperty(
"XMax", std::vector<double>(1,
tmax));
1030 alg->setProperty(
"InputWorkspace", matrixws);
1031 alg->setProperty(
"OutputWorkspace", matrixws);
1041 g_log.
information() <<
" ) started at " << Types::Core::DateAndTime::getCurrentTime() <<
"\n";
1044 alg->executeAsChildAlg();
1045 matrixws = alg->getProperty(
"OutputWorkspace");
1056 size_t nspec1 = ws1->getNumberHistograms();
1058 std::vector<specnum_t> origspecNos;
1059 for (
size_t i = 0; i < nspec1; ++i) {
1060 specnum_t tmpspecNo = ws1->getSpectrum(i).getSpectrumNo();
1061 origspecNos.emplace_back(tmpspecNo);
1062 if (tmpspecNo > maxspecNo1)
1063 maxspecNo1 = tmpspecNo;
1066 g_log.
information() <<
"[DBx536] Max spectrum number of ws1 = " << maxspecNo1 <<
", Offset = " << offset <<
".\n";
1068 size_t nspec2 = ws2->getNumberHistograms();
1075 alg->setProperty(
"InputWorkspace1", ws1);
1076 alg->setProperty(
"InputWorkspace2", ws2);
1077 alg->setProperty(
"OutputWorkspace", ws1);
1078 alg->setProperty(
"ValidateInputs",
false);
1080 alg->executeAsChildAlg();
1085 for (
size_t i = 0; i < nspec1; ++i) {
1086 specnum_t tmpspecNo = outws->getSpectrum(i).getSpectrumNo();
1087 outws->getSpectrum(i).setSpectrumNo(origspecNos[i]);
1089 g_log.
information() <<
"[DBx540] Conjoined spectrum " << i <<
": restore spectrum number to "
1090 << outws->getSpectrum(i).getSpectrumNo() <<
" from spectrum number = " << tmpspecNo <<
".\n";
1095 for (
size_t i = 0; i < nspec2; ++i) {
1097 outws->getSpectrum(nspec1 + i).setSpectrumNo(newspecid);
1112 alg->setProperty(
"OffsetsWorkspace", offsetsWS);
1113 alg->setPropertyValue(
"OutputWorkspace",
m_instName +
"_cal");
1114 alg->executeAsChildAlg();
1128 if ((!
m_groupWS) && (!calFilename.empty()) && (!groupFilename.empty())) {
1129 if (AnalysisDataService::Instance().doesExist(
m_instName +
"_group"))
1137 if (AnalysisDataService::Instance().doesExist(
m_instName +
"_cal"))
1140 if (AnalysisDataService::Instance().doesExist(
m_instName +
"_offsets")) {
1147 if ((!
m_maskWS) && (!calFilename.empty())) {
1148 if (AnalysisDataService::Instance().doesExist(
m_instName +
"_mask"))
1157 if (calFilename.empty() && groupFilename.empty())
1165 if (calFilename.empty()) {
1166 g_log.
information() <<
"Loading Grouping file \"" << groupFilename <<
"\"\n";
1169 alg->setProperty(
"InputFile", groupFilename);
1170 alg->setProperty(
"InputWorkspace",
m_inputW);
1171 alg->executeAsChildAlg();
1173 m_groupWS = alg->getProperty(
"OutputWorkspace");
1174 const std::string groupname =
m_instName +
"_group";
1175 AnalysisDataService::Instance().addOrReplace(groupname,
m_groupWS);
1176 this->setPropertyValue(PropertyNames::GROUP_WKSP, groupname);
1178 g_log.
information() <<
"Loading Calibration file \"" << calFilename <<
"\"";
1179 if (!groupFilename.empty())
1184 alg->setProperty(
"InputWorkspace",
m_inputW);
1185 alg->setPropertyValue(
"Filename", calFilename);
1186 alg->setPropertyValue(
"GroupFilename", groupFilename);
1187 alg->setProperty<
bool>(
"MakeCalWorkspace", loadCalibration);
1188 alg->setProperty<
bool>(
"MakeGroupingWorkspace", loadGrouping);
1189 alg->setProperty<
bool>(
"MakeMaskWorkspace", loadMask);
1190 alg->setProperty<
double>(
"TofMin",
getProperty(
"TMin"));
1191 alg->setProperty<
double>(
"TofMax",
getProperty(
"TMax"));
1192 alg->setPropertyValue(
"WorkspaceName",
m_instName);
1193 alg->executeAsChildAlg();
1197 m_groupWS = alg->getProperty(
"OutputGroupingWorkspace");
1199 const std::string groupname =
m_instName +
"_group";
1200 AnalysisDataService::Instance().addOrReplace(groupname,
m_groupWS);
1201 this->setPropertyValue(PropertyNames::GROUP_WKSP, groupname);
1203 if (loadCalibration) {
1206 const std::string calname =
m_instName +
"_cal";
1207 AnalysisDataService::Instance().addOrReplace(calname,
m_calibrationWS);
1208 this->setPropertyValue(PropertyNames::CAL_WKSP, calname);
1211 m_maskWS = alg->getProperty(
"OutputMaskWorkspace");
1213 const std::string maskname =
m_instName +
"_mask";
1214 AnalysisDataService::Instance().addOrReplace(maskname,
m_maskWS);
1215 this->setPropertyValue(PropertyNames::MASK_WKSP, maskname);
1221 const double wallClockTolerance) {
1222 if (compressEventsTolerance == 0.)
1225 if (
auto outputEW = std::dynamic_pointer_cast<EventWorkspace>(
m_outputW)) {
1226 g_log.
information() <<
"running CompressEvents(Tolerance=" << compressEventsTolerance;
1227 if (!isEmpty(wallClockTolerance))
1229 g_log.
information() <<
") started at " << Types::Core::DateAndTime::getCurrentTime() <<
"\n";
1231 compressAlg->setProperty(
"InputWorkspace", outputEW);
1232 compressAlg->setProperty(
"OutputWorkspace", outputEW);
1233 compressAlg->setProperty(
"Tolerance", compressEventsTolerance);
1234 if (!isEmpty(wallClockTolerance)) {
1235 compressAlg->setProperty(
"WallClockTolerance", wallClockTolerance);
1236 compressAlg->setPropertyValue(
"StartTime",
getPropertyValue(PropertyNames::COMPRESS_WALL_START));
1238 compressAlg->executeAsChildAlg();
1239 outputEW = compressAlg->getProperty(
"OutputWorkspace");
1240 m_outputW = std::dynamic_pointer_cast<MatrixWorkspace>(outputEW);
1250 const double tofmax,
const bool hasWallClockTolerance) {
1252 if (hasWallClockTolerance)
1255 if (compressTolerance == 0.)
1258 if (
const auto eventWS = std::dynamic_pointer_cast<const EventWorkspace>(
m_outputW)) {
1261 double tofmin_wksp = tofmin;
1262 double tofmax_wksp = tofmax;
1263 if (isEmpty(tofmin) || isEmpty(tofmax))
1264 getTofRange(
m_outputW, tofmin_wksp, tofmax_wksp);
1265 const double tofRange = std::fabs(tofmax_wksp - tofmin_wksp);
1268 constexpr double TOF_EVENT_BYTE_SIZE{
static_cast<double>(
sizeof(Types::Event::TofEvent))};
1269 constexpr double WEIGHTED_EVENT_BYTE_SIZE{
static_cast<double>(
sizeof(
WeightedEvent))};
1270 constexpr double WEIGHTED_NOTIME_EVENT_BYTE_SIZE{
static_cast<double>(
sizeof(
WeightedEventNoTime))};
1274 double sizeWeightedEventsEstimate;
1275 if (compressTolerance > 0)
1276 sizeWeightedEventsEstimate = WEIGHTED_NOTIME_EVENT_BYTE_SIZE * tofRange / compressTolerance;
1278 if (tofmin_wksp < 0)
1281 if (tofmin_wksp == 0)
1282 tofmin_wksp = compressTolerance;
1284 sizeWeightedEventsEstimate =
1285 WEIGHTED_NOTIME_EVENT_BYTE_SIZE * log(tofmax_wksp / tofmin_wksp) / log1p(abs(compressTolerance));
1288 double numEvents =
static_cast<double>(eventWS->getNumberEvents());
1289 const auto eventType = eventWS->getEventType();
1306 <<
" and comparing to " << sizeWeightedEventsEstimate <<
"\n";
1307 return sizeWeightedEventsEstimate <
numEvents;
#define DECLARE_ALGORITHM(classname)
A specialized class for dealing with file properties.
@ OptionalLoad
to specify a file to read but the file doesn't have to exist
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) override
Create a Child Algorithm.
Kernel::IPropertyManager::TypedValue getProperty(const std::string &name) const override
Get the property held by this object.
std::string getPropertyValue(const std::string &name) const override
Get the property held by this object.
ITableWorkspace is an implementation of Workspace in which the data are organised in columns of same ...
Base MatrixWorkspace Abstract Class.
A property class for workspaces.
A GroupingWorkspace is a subclass of Workspace2D where each spectrum has a single number entry,...
An OffsetsWorkspace is a specialized Workspace2D where the Y value at each pixel is the offset to be ...
Info about a single neutron detection event, including a weight and error value, but excluding the pu...
Info about a single neutron detection event, including a weight and error value:
Support for a property that holds an array of values.
Exception for when an item is not found in a collection.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
This is a parent algorithm that uses several different child algorithms to perform it's task.
void exec() override
Executes the algorithm.
void loadCalFile(const std::string &calFilename, const std::string &groupFilename)
Loads the .cal file if necessary.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
API::MatrixWorkspace_sptr m_inputW
API::MatrixWorkspace_sptr diffractionFocusRaggedRebinInDspace(API::MatrixWorkspace_sptr ws)
Call diffraction focus to a matrix workspace with ragged rebin parameters.
DataObjects::GroupingWorkspace_sptr m_groupWS
std::vector< double > m_dmins
bool shouldCompressUnfocused(const double compressTolerance, const double tofmin, const double tofmax, const bool hasWallClockTolerance)
Return true if a rough estimate suggests that the size of the events will be smaller after compressin...
API::MatrixWorkspace_sptr m_lowResW
Low resolution TOF matrix workspace.
void convertOffsetsToCal(DataObjects::OffsetsWorkspace_sptr &offsetsWS)
API::ITableWorkspace_sptr m_calibrationWS
API::MatrixWorkspace_sptr editInstrument(API::MatrixWorkspace_sptr ws, const std::vector< double > &polars, const std::vector< specnum_t > &specids, const std::vector< double > &l2s, const std::vector< double > &phis)
Call edit instrument geometry.
std::vector< double > l2s
size_t m_lowResSpecOffset
Offset to low resolution TOF spectra.
API::MatrixWorkspace_sptr diffractionFocus(API::MatrixWorkspace_sptr ws)
Call diffraction focus to a matrix workspace.
std::unique_ptr< API::Progress > m_progress
Progress reporting.
DataObjects::EventWorkspace_sptr m_lowResEW
Low resolution TOF event workspace.
std::vector< int32_t > specids
DataObjects::MaskWorkspace_sptr m_maskWS
API::MatrixWorkspace_sptr filterResonances(API::MatrixWorkspace_sptr matrixws)
Filter out absorption resonances.
std::vector< double > m_params
std::vector< double > tths
std::vector< double > m_resonanceLower
std::vector< double > m_resonanceUpper
std::vector< double > m_delta_ragged
API::MatrixWorkspace_sptr rebinRagged(API::MatrixWorkspace_sptr matrixws, const bool inDspace)
RebinRagged this should only be done on the final focussed workspace.
API::MatrixWorkspace_sptr m_outputW
double getVecPropertyFromPmOrSelf(const std::string &name, std::vector< double > &avec)
Function to get a vector property either from a PropertyManager or the algorithm properties.
API::MatrixWorkspace_sptr convertUnits(API::MatrixWorkspace_sptr matrixws, const std::string &target)
Convert units.
bool m_processLowResTOF
Flag to process low resolution workspace.
API::MatrixWorkspace_sptr rebin(API::MatrixWorkspace_sptr matrixws)
Rebin.
std::vector< double > phis
void compressEventsOutputWS(const double compressEventsTolerance, const double wallClockTolerance)
std::vector< double > m_dmaxs
API::MatrixWorkspace_sptr conjoinWorkspaces(const API::MatrixWorkspace_sptr &ws1, const API::MatrixWorkspace_sptr &ws2, size_t offset)
Add workspace2 to workspace1 by adding spectrum.
std::map< std::string, std::string > validateInputs() override
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::size_t numEvents(Nexus::File &file, bool &hasTotalCounts, bool &oldNeXusFileNames, const std::string &prefix, const Nexus::NexusDescriptor &descriptor)
Get the number of events in the currently opened group.
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
std::shared_ptr< OffsetsWorkspace > OffsetsWorkspace_sptr
shared pointer to the OffsetsWorkspace 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::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
const std::string BINMODE("BinningMode")
const std::string OUTPUT_WKSP("OutputWorkspace")
const std::string INPUT_WKSP("InputWorkspace")
RegLowVectorPair< NumT > splitVectors(const std::vector< NumT > &orig, const size_t numVal, const std::string &label)
int32_t specnum_t
Typedef for a spectrum Number.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ InOut
Both an input & output workspace.
@ Input
An input workspace.
@ Output
An output workspace.