Commit b4f51141 authored by Gagik Vardanyan's avatar Gagik Vardanyan
Browse files

implemented time aware chopper gap unit and chopper window value

parent ff4d65ce
......@@ -11,6 +11,7 @@
#include "MantidDataHandling/LoadHelper.h"
#include "MantidKernel/NexusDescriptor.h"
#include "MantidNexus/NexusClasses.h"
#include "MantidTypes/Core/DateAndTime.h"
namespace Mantid {
namespace DataHandling {
......@@ -96,6 +97,7 @@ private:
double m_sampleZOffset{0.0};
double m_sourceDistance{0.0};
Mantid::DataHandling::LoadHelper m_loader;
Mantid::Types::Core::DateAndTime m_startTime;
};
} // namespace DataHandling
......
......@@ -29,7 +29,11 @@
#include "MantidKernel/UnitFactory.h"
#include "MantidKernel/V3D.h"
using Mantid::Types::Core::DateAndTime;
namespace {
const DateAndTime CYCLE203TIME = DateAndTime("2020-07-31T23:59:59");
/// Component coordinates for FIGARO, in meter.
namespace FIGARO {
constexpr double DH1Z{1.135}; // Motor DH1 horizontal position
......@@ -390,6 +394,9 @@ void LoadILLReflectometry::loadDataDetails(NeXus::NXEntry &entry) {
// PSD data D17 256 x 1 x 1000
// PSD data FIGARO 1 x 256 x 1000
m_startTime =
DateAndTime(m_loader.dateTimeInIsoFormat(entry.getString("start_time")));
if (m_acqMode) {
NXFloat timeOfFlight = entry.openNXFloat("instrument/PSD/time_of_flight");
timeOfFlight.load();
......@@ -540,7 +547,19 @@ std::vector<double> LoadILLReflectometry::getXValues() {
g_log.error() << "First chopper velocity " << chop1Speed
<< ". Check you NeXus file.\n";
}
const double chopWindow = 45.0;
double chopWindow = 45.0;
if (m_startTime > CYCLE203TIME) {
// this is a workaround for the chopper window which has a different
// value since cycle 203 at the moment it is not possible to achieve
// this via IPF without duplicating the IDF neither it is properly
// written in the nexus, so this is the only solution
chopWindow = 20.;
}
m_localWorkspace->mutableRun().addProperty("ChopperWindow", chopWindow,
"degree", true);
g_log.debug() << "Chopper Opening Window [degrees]" << chopWindow << '\n';
const double t_TOF2 = m_tofDelay - 1.e+6 * 60.0 *
(POFF - chopWindow + chop2Phase -
chop1Phase + openOffset) /
......@@ -937,13 +956,15 @@ double LoadILLReflectometry::sampleHorizontalOffset() const {
*/
double LoadILLReflectometry::sourceSampleDistance() const {
if (m_instrument != Supported::FIGARO) {
// the Distance.ChopperGap in the nexus file was initially in cm, then in m,
// now in mm between the first two generations we can flag on the
// dist_chop_samp vs MidChopper_Sample_distance however between the 2nd and
// 3rd we have to check the time, since all the rest is consistent
double pairCentre;
double pairSeparation;
try {
pairCentre = doubleFromRun("VirtualChopper.dist_chop_samp"); // in [m]
pairSeparation = doubleFromRun("Distance.ChopperGap") / 100; // in [m]
m_localWorkspace->mutableRun().addProperty("Distance.ChopperGap",
pairSeparation, "meter", true);
m_localWorkspace->mutableRun().addProperty(
"VirtualChopper.dist_chop_samp", pairCentre, "meter", true);
pairCentre -= 0.5 * pairSeparation;
......@@ -952,8 +973,9 @@ double LoadILLReflectometry::sourceSampleDistance() const {
pairCentre = mmToMeter(doubleFromRun(
"VirtualChopper.MidChopper_Sample_distance")); // in [m]
pairSeparation = doubleFromRun("Distance.ChopperGap"); // in [m]
m_localWorkspace->mutableRun().addProperty(
"Distance.ChopperGap", pairSeparation, "meter", true);
if (m_startTime > CYCLE203TIME) {
pairSeparation = mmToMeter(pairSeparation);
}
m_localWorkspace->mutableRun().addProperty(
"VirtualChopper.MidChopper_Sample_distance", pairCentre, "meter",
true);
......@@ -962,6 +984,8 @@ double LoadILLReflectometry::sourceSampleDistance() const {
"Unable to extract chopper to sample distance");
}
}
m_localWorkspace->mutableRun().addProperty("Distance.ChopperGap",
pairSeparation, "meter", true);
return pairCentre;
} else {
const double chopperDist =
......
......@@ -28,6 +28,7 @@ class LoadILLReflectometryTest : public CxxTest::TestSuite {
private:
const std::string m_d17DirectBeamFile{"ILL/D17/317369.nxs"};
const std::string m_d17File{"ILL/D17/317370.nxs"};
const std::string m_d17Cycle203File{"ILL/D17/564343.nxs"};
const std::string m_figaroFile{"ILL/Figaro/598488.nxs"};
const std::string m_d17File_2018{"ILL/D17/000001.nxs"};
const std::string m_figaroFile_2018{"ILL/Figaro/000002.nxs"};
......@@ -157,10 +158,11 @@ public:
run.getPropertyValueAsType<double>("VirtualChopper.poff");
const auto openOffset =
run.getPropertyValueAsType<double>("VirtualChopper.open_offset");
const auto chopperWindow = run.getPropertyValueAsType<double>("ChopperWindow");
const auto tof0 =
tofDelay -
60.e6 * (pOffset - 45. + chopper2Phase - chopper1Phase + openOffset) /
(2. * 360. * chopper1Speed);
(2. * 360. * chopper1Speed);
TS_ASSERT_EQUALS(output->blocksize(), channelCount)
for (size_t i = 0; i < output->getNumberHistograms(); ++i) {
const auto &xs = output->x(i);
......@@ -180,6 +182,18 @@ public:
run.getProperty("VirtualChopper.chopper2_phase_average")->units(), "")
TS_ASSERT_EQUALS(run.getProperty("VirtualChopper.poff")->units(), "")
TS_ASSERT_EQUALS(run.getProperty("VirtualChopper.open_offset")->units(), "")
TS_ASSERT_EQUALS(chopperWindow, 45.)
}
void testD17Cycle203ChopperWindow() {
MatrixWorkspace_sptr output;
auto prop = emptyProperties();
prop.emplace_back("XUnit", "TimeOfFlight");
getWorkspaceFor(output, m_d17Cycle203File, m_outWSName, prop);
TS_ASSERT_EQUALS(
output->run().getPropertyValueAsType<double>("ChopperWindow"), 20.)
TS_ASSERT_EQUALS(output->run().getPropertyValueAsType<double>("ChopperGap"),
0.082)
}
void testTOFFigaro() {
......
......@@ -42,12 +42,13 @@ def chopperOpeningAngle(sampleLogs, instrumentName):
"""Return the chopper opening angle in degrees."""
if instrumentName == 'D17':
chopper1Phase = sampleLogs.getProperty('VirtualChopper.chopper1_phase_average').value
chopperWindow = sampleLogs.getProperty('ChopperWindow').value
if chopper1Phase > 360.:
# Workaround for broken old D17 NeXus files.
chopper1Phase = sampleLogs.getProperty('VirtualChopper.chopper2_speed_average').value
chopper2Phase = sampleLogs.getProperty('VirtualChopper.chopper2_phase_average').value
openoffset = sampleLogs.getProperty('VirtualChopper.open_offset').value
return 45. - (chopper2Phase - chopper1Phase) - openoffset
return chopperWindow - (chopper2Phase - chopper1Phase) - openoffset
else:
firstChopper = int(sampleLogs.getProperty('ChopperSetting.firstChopper').value)
secondChopper = int(sampleLogs.getProperty('ChopperSetting.secondChopper').value)
......
6a49b4d3655c1e3cfa5e5b2b72e61afb
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment