Skip to content

Commit d523b88

Browse files
committed
Add loading cal file and change output to be d-spacing
1 parent 480e6eb commit d523b88

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

Framework/DataHandling/inc/MantidDataHandling/AlignAndFocusPowderSlim.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class MANTID_DATAHANDLING_DLL AlignAndFocusPowderSlim : public API::Algorithm {
4949
void loadPulseTimes(std::unique_ptr<std::vector<double>> &data, ::NeXus::File &h5file);
5050
void loadEventIndex(std::unique_ptr<std::vector<uint64_t>> &data, ::NeXus::File &h5file);
5151

52-
std::map<detid_t, double> m_calibration;
52+
void loadCalFile(const Mantid::API::Workspace_sptr &inputWS, const std::string &filename);
53+
54+
std::map<detid_t, double> m_calibration; // detid: 1/difc
5355
bool is_time_filtered{false};
5456
size_t pulse_start_index{0};
5557
size_t pulse_stop_index{std::numeric_limits<size_t>::max()};

Framework/DataHandling/src/AlignAndFocusPowderSlim.cpp

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "MantidDataHandling/LoadEventNexus.h"
1414
#include "MantidDataHandling/LoadEventNexusIndexSetup.h"
1515
#include "MantidDataObjects/EventList.h"
16+
#include "MantidDataObjects/TableWorkspace.h"
1617
#include "MantidGeometry/Instrument/DetectorInfo.h"
1718
#include "MantidKernel/Timer.h"
1819
#include "MantidKernel/VectorHelper.h"
@@ -25,6 +26,7 @@
2526

2627
namespace Mantid::DataHandling {
2728
using Mantid::API::FileProperty;
29+
using Mantid::API::ITableWorkspace_sptr;
2830
using Mantid::API::MatrixWorkspace_sptr;
2931
using Mantid::API::WorkspaceFactory;
3032
using Mantid::API::WorkspaceProperty;
@@ -197,6 +199,10 @@ void AlignAndFocusPowderSlim::init() {
197199
Direction::Input),
198200
"Optional: To only include events before the provided stop "
199201
"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.");
200206
declareProperty(
201207
std::make_unique<WorkspaceProperty<API::MatrixWorkspace>>(PropertyNames::OUTPUT_WKSP, "", Direction::Output),
202208
"An output workspace.");
@@ -208,16 +214,16 @@ void AlignAndFocusPowderSlim::init() {
208214
void AlignAndFocusPowderSlim::exec() {
209215
// create a histogram workspace
210216
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};
213219

214220
// These give the limits in each file as to which events we actually load
215221
// (when filtering by time).
216222
loadStart.resize(1, 0);
217223
loadSize.resize(1, 0);
218224

219225
HistogramData::BinEdges XValues_new(0);
220-
const double binWidth{10.};
226+
const double binWidth{1.6e-3}; // to get 1250 bins total
221227
const bool linearBins = bool(binWidth > 0.);
222228
UNUSED_ARG(Kernel::VectorHelper::createAxisFromRebinParams({xmin, binWidth, xmax}, XValues_new.mutableRawData(), true,
223229
false, xmin, xmax));
@@ -236,7 +242,13 @@ void AlignAndFocusPowderSlim::exec() {
236242
// prog->doReport("Loading instrument"); TODO add progress bar stuff
237243
// LoadEventNexus::loadInstrument<MatrixWorkspace_sptr>(filename, wksp, "entry", this, &descriptor);
238244
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+
}
240252

241253
/*
242254
// load run metadata
@@ -398,12 +410,10 @@ void AlignAndFocusPowderSlim::exec() {
398410

399411
void AlignAndFocusPowderSlim::initCalibrationConstants(API::MatrixWorkspace_sptr &wksp) {
400412
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.);
403413

404414
for (auto iter = detInfo.cbegin(); iter != detInfo.cend(); ++iter) {
405415
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()));
407417
}
408418
}
409419
}
@@ -504,6 +514,24 @@ void AlignAndFocusPowderSlim::loadEventIndex(std::unique_ptr<std::vector<uint64_
504514
h5file.closeData();
505515
}
506516

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+
507535
// ------------------------ BankCalibration object
508536
AlignAndFocusPowderSlim::BankCalibration::BankCalibration(const detid_t idmin, const detid_t idmax,
509537
const std::map<detid_t, double> &calibration_map)

0 commit comments

Comments
 (0)