13
13
#include " MantidDataHandling/LoadEventNexus.h"
14
14
#include " MantidDataHandling/LoadEventNexusIndexSetup.h"
15
15
#include " MantidDataObjects/EventList.h"
16
+ #include " MantidDataObjects/TableWorkspace.h"
16
17
#include " MantidGeometry/Instrument/DetectorInfo.h"
17
18
#include " MantidKernel/Timer.h"
18
19
#include " MantidKernel/VectorHelper.h"
25
26
26
27
namespace Mantid ::DataHandling {
27
28
using Mantid::API::FileProperty;
29
+ using Mantid::API::ITableWorkspace_sptr;
28
30
using Mantid::API::MatrixWorkspace_sptr;
29
31
using Mantid::API::WorkspaceFactory;
30
32
using Mantid::API::WorkspaceProperty;
@@ -197,6 +199,10 @@ void AlignAndFocusPowderSlim::init() {
197
199
Direction::Input),
198
200
" Optional: To only include events before the provided stop "
199
201
" time, in seconds (relative to the start of the run)." );
202
+ const std::vector<std::string> cal_exts{" .h5" , " .hd5" , " .hdf" , " .cal" };
203
+ declareProperty (std::make_unique<FileProperty>(PropertyNames::CAL_FILE, " " , FileProperty::OptionalLoad, cal_exts),
204
+ " Optional: The .cal file containing the position correction factors. "
205
+ " Either this or OffsetsWorkspace needs to be specified." );
200
206
declareProperty (
201
207
std::make_unique<WorkspaceProperty<API::MatrixWorkspace>>(PropertyNames::OUTPUT_WKSP, " " , Direction::Output),
202
208
" An output workspace." );
@@ -208,16 +214,16 @@ void AlignAndFocusPowderSlim::init() {
208
214
void AlignAndFocusPowderSlim::exec () {
209
215
// create a histogram workspace
210
216
constexpr size_t numHist{6 };
211
- constexpr double xmin{6463 };
212
- constexpr double xmax{39950 };
217
+ constexpr double xmin{0.25 };
218
+ constexpr double xmax{2.25 };
213
219
214
220
// These give the limits in each file as to which events we actually load
215
221
// (when filtering by time).
216
222
loadStart.resize (1 , 0 );
217
223
loadSize.resize (1 , 0 );
218
224
219
225
HistogramData::BinEdges XValues_new (0 );
220
- const double binWidth{10 .};
226
+ const double binWidth{1.6e-3 }; // to get 1250 bins total
221
227
const bool linearBins = bool (binWidth > 0 .);
222
228
UNUSED_ARG (Kernel::VectorHelper::createAxisFromRebinParams ({xmin, binWidth, xmax}, XValues_new.mutableRawData (), true ,
223
229
false , xmin, xmax));
@@ -236,7 +242,13 @@ void AlignAndFocusPowderSlim::exec() {
236
242
// prog->doReport("Loading instrument"); TODO add progress bar stuff
237
243
// LoadEventNexus::loadInstrument<MatrixWorkspace_sptr>(filename, wksp, "entry", this, &descriptor);
238
244
LoadEventNexus::loadInstrument<MatrixWorkspace_sptr>(filename, wksp, ENTRY_TOP_LEVEL, this , &descriptor);
239
- this ->initCalibrationConstants (wksp);
245
+
246
+ const std::string cal_filename = getPropertyValue (PropertyNames::CAL_FILE);
247
+ if (!cal_filename.empty ()) {
248
+ loadCalFile (wksp, cal_filename);
249
+ } else {
250
+ this ->initCalibrationConstants (wksp);
251
+ }
240
252
241
253
/*
242
254
// load run metadata
@@ -398,12 +410,10 @@ void AlignAndFocusPowderSlim::exec() {
398
410
399
411
void AlignAndFocusPowderSlim::initCalibrationConstants (API::MatrixWorkspace_sptr &wksp) {
400
412
const auto detInfo = wksp->detectorInfo ();
401
- // TODO currently arbitrary
402
- const auto difCFocus = 1 . / Kernel::Units::tofToDSpacingFactor (detInfo.l1 (), 1 ., 0.5 * M_PI, 0 .);
403
413
404
414
for (auto iter = detInfo.cbegin (); iter != detInfo.cend (); ++iter) {
405
415
if (!iter->isMonitor ()) {
406
- m_calibration.emplace (iter->detid (), difCFocus / detInfo.difcUncalibrated (iter->index ()));
416
+ m_calibration.emplace (iter->detid (), 1 . / detInfo.difcUncalibrated (iter->index ()));
407
417
}
408
418
}
409
419
}
@@ -504,6 +514,24 @@ void AlignAndFocusPowderSlim::loadEventIndex(std::unique_ptr<std::vector<uint64_
504
514
h5file.closeData ();
505
515
}
506
516
517
+ void AlignAndFocusPowderSlim::loadCalFile (const Mantid::API::Workspace_sptr &inputWS, const std::string &filename) {
518
+ auto alg = createChildAlgorithm (" LoadDiffCal" );
519
+ alg->setProperty (" InputWorkspace" , inputWS);
520
+ alg->setPropertyValue (" Filename" , filename);
521
+ alg->setProperty <bool >(" MakeCalWorkspace" , true );
522
+ alg->setProperty <bool >(" MakeGroupingWorkspace" , false );
523
+ alg->setProperty <bool >(" MakeMaskWorkspace" , false );
524
+ alg->setPropertyValue (" WorkspaceName" , " temp" );
525
+ alg->executeAsChildAlg ();
526
+
527
+ const ITableWorkspace_sptr calibrationWS = alg->getProperty (" OutputCalWorkspace" );
528
+ for (size_t row = 0 ; row < calibrationWS->rowCount (); ++row) {
529
+ const detid_t detid = calibrationWS->cell <int >(row, 0 );
530
+ const double detc = calibrationWS->cell <double >(row, 1 );
531
+ m_calibration.emplace (detid, 1 . / detc);
532
+ }
533
+ }
534
+
507
535
// ------------------------ BankCalibration object
508
536
AlignAndFocusPowderSlim::BankCalibration::BankCalibration (const detid_t idmin, const detid_t idmax,
509
537
const std::map<detid_t , double > &calibration_map)
0 commit comments