Commit 6ee778bc authored by Ian Bush's avatar Ian Bush
Browse files

Refs #17861 LoadILLTOF to calculate pulse intervals

parent 1ea083cc
......@@ -68,6 +68,7 @@ private:
void initInstrumentSpecific();
void addAllNexusFieldsAsProperties(std::string filename);
void addEnergyToRun();
void addPulseInterval();
int getDetectorElasticPeakPosition(const NeXus::NXInt &data);
void loadTimeDetails(NeXus::NXEntry &entry);
......
......@@ -119,6 +119,7 @@ void LoadILLTOF::exec() {
calculatedDetectorElasticPeakPosition);
addEnergyToRun();
addPulseInterval();
// load the instrument from the IDF if it exists
runLoadInstrument();
......@@ -352,6 +353,35 @@ void LoadILLTOF::addEnergyToRun() {
runDetails.addProperty<double>("Ei", ei, true); // overwrite
}
/**
* Calculate and add the pulse intervals for the run
*/
void LoadILLTOF::addPulseInterval() {
API::Run &runDetails = m_localWorkspace->mutableRun();
double pulseInterval;
if (m_instrumentName == "IN4") {
double fermiChopperSpeed = runDetails.getPropertyAsSingleValue("FC.rotation_speed");
double bkgChopper1Speed = runDetails.getPropertyAsSingleValue("BC1.rotation_speed");
double bkgChopper2Speed = runDetails.getPropertyAsSingleValue("BC2.rotation_speed");
if (std::abs(bkgChopper1Speed - bkgChopper2Speed) > 1) {
throw std::invalid_argument("Background choppers 1 and 2 have different speeds");
}
double n = fermiChopperSpeed / bkgChopper1Speed / 4;
pulseInterval = 60.0 / (2 * fermiChopperSpeed) * n;
} else if (m_instrumentName == "IN6") {
double fermiChopperSpeed = runDetails.getPropertyAsSingleValue("Fermi.rotation_speed");
double suppressorSpeed = runDetails.getPropertyAsSingleValue("Suppressor.rotation_speed");
double n = fermiChopperSpeed / suppressorSpeed;
pulseInterval = 60.0 / (2 * fermiChopperSpeed) * n;
}
runDetails.addProperty<double>("pulse_interval", pulseInterval);
}
/**
* Gets the experimental Elastic Peak Position in the dectector
* as the value parsed from the nexus file might be wrong.
......
......@@ -16,6 +16,10 @@ public:
static LoadILLTOFTest *createSuite() { return new LoadILLTOFTest(); }
static void destroySuite(LoadILLTOFTest *suite) { delete suite; }
void tearDown() override {
AnalysisDataService::Instance().clear();
}
void testName() {
LoadILLTOF loader;
TS_ASSERT_EQUALS(loader.name(), "LoadILLTOF");
......@@ -36,7 +40,7 @@ public:
* This test only loads the Sample Data
* The elastic peak is obtained on the fly from the sample data.
*/
void loadDataFile(const std::string dataFile, const int numberOfHistograms) {
MatrixWorkspace_sptr loadDataFile(const std::string dataFile, const int numberOfHistograms) {
LoadILLTOF loader;
loader.initialize();
loader.setPropertyValue("Filename", dataFile);
......@@ -53,12 +57,26 @@ public:
TS_ASSERT_EQUALS(output2D->getNumberHistograms(), numberOfHistograms);
AnalysisDataService::Instance().clear();
return output2D;
}
void test_IN4_load() { loadDataFile("ILL/IN4/084446.nxs", 397); }
void test_IN5_load() { loadDataFile("ILL/IN5/104007.nxs", 98305); }
void test_IN6_load() { loadDataFile("ILL/IN6/164192.nxs", 340); }
void test_IN4_load() {
MatrixWorkspace_sptr ws = loadDataFile("ILL/IN4/084446.nxs", 397);
double pulseInterval = ws->run().getLogAsSingleValue("pulse_interval");
TS_ASSERT_DELTA(0.003, pulseInterval, 1e-10);
}
void test_IN5_load() {
loadDataFile("ILL/IN5/104007.nxs", 98305);
}
void test_IN6_load() {
MatrixWorkspace_sptr ws = loadDataFile("ILL/IN6/164192.nxs", 340);
double pulseInterval = ws->run().getLogAsSingleValue("pulse_interval");
TS_ASSERT_DELTA(0.0060337892, pulseInterval, 1e-10);
}
};
//------------------------------------------------------------------------------
......
Markdown is supported
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