Commit 935b0ad1 authored by Ricardo Leal's avatar Ricardo Leal
Browse files

Re #7452 Added monitor info + fix non tof Q calculation

parent 7e95908f
......@@ -74,6 +74,9 @@ private:
const std::string &);
void initWorkSpace(NeXus::NXEntry&, const std::string&);
void createEmptyWorkspace(int, int);
size_t loadDataIntoWorkspaceFromMonitors(NeXus::NXEntry &firstEntry, size_t firstIndex = 0);
size_t loadDataIntoWorkspaceFromHorizontalTubes(NeXus::NXInt &, const std::vector<double> &,
size_t);
size_t loadDataIntoWorkspaceFromVerticalTubes(NeXus::NXInt &, const std::vector<double> &,
......
......@@ -10,6 +10,9 @@
#include "MantidAPI/RegisterFileLoader.h"
#include "MantidKernel/UnitFactory.h"
#include <numeric> //for std::iota
#include <algorithm>
#include <limits>
namespace Mantid {
namespace DataHandling {
......@@ -208,7 +211,8 @@ void LoadILLSANS::initWorkSpace(NeXus::NXEntry &firstEntry,
+ dataDown.dim0() * dataDown.dim1() + dataUp.dim0() * dataUp.dim1();
g_log.debug("Creating empty workspace...");
createEmptyWorkspace(numberOfHistograms, dataRear.dim2());
// TODO : Must put this 2 somewhere else: number of monitors!
createEmptyWorkspace(numberOfHistograms+2, dataRear.dim2());
loadMetaData(firstEntry, instrumentPath);
......@@ -241,13 +245,43 @@ void LoadILLSANS::initWorkSpace(NeXus::NXEntry &firstEntry,
binPathPrefix + "5");
}
g_log.debug("Loading the data into the workspace...");
size_t nextIndex = loadDataIntoWorkspaceFromHorizontalTubes(dataRear,binningRear,0);
size_t nextIndex = loadDataIntoWorkspaceFromMonitors(firstEntry,0);
nextIndex = loadDataIntoWorkspaceFromHorizontalTubes(dataRear,binningRear,nextIndex);
nextIndex = loadDataIntoWorkspaceFromVerticalTubes(dataRight,binningRight,nextIndex);
nextIndex = loadDataIntoWorkspaceFromVerticalTubes(dataLeft,binningLeft,nextIndex);
nextIndex = loadDataIntoWorkspaceFromHorizontalTubes(dataDown,binningDown,nextIndex);
nextIndex = loadDataIntoWorkspaceFromHorizontalTubes(dataUp,binningUp,nextIndex);
}
size_t LoadILLSANS::loadDataIntoWorkspaceFromMonitors(NeXus::NXEntry &firstEntry, size_t firstIndex) {
// let's find the monitors
// For D33 should be monitor1 and monitor2
for (std::vector<NXClassInfo>::const_iterator it =
firstEntry.groups().begin(); it != firstEntry.groups().end(); ++it) {
if (it->nxclass == "NXmonitor") {
NXData dataGroup = firstEntry.openNXData(it->nxname);
NXInt data = dataGroup.openIntData();
data.load();
g_log.debug() << "Monitor: " << it->nxname << " dims = " << data.dim0() << "x"<< data.dim1() << "x"<< data.dim2() << std::endl;
std::vector<double> positionsBinning(data.dim2() + 1);
std::iota(positionsBinning.begin(), positionsBinning.end(), 0);
// Assign X
m_localWorkspace->dataX(firstIndex).assign(positionsBinning.begin(),positionsBinning.end());
// Assign Y
m_localWorkspace->dataY(firstIndex).assign(data(), data() + data.dim2());
// Assign Error
MantidVec& E = m_localWorkspace->dataE(firstIndex);
std::transform(data(), data() + data.dim2(), E.begin(),LoadHelper::calculateStandardError);
firstIndex++;
}
}
return firstIndex;
}
size_t LoadILLSANS::loadDataIntoWorkspaceFromHorizontalTubes(NeXus::NXInt &data,
const std::vector<double> &timeBinning, size_t firstIndex = 0) {
......@@ -532,35 +566,38 @@ double LoadILLSANS::calculateQ(const double lambda, const double twoTheta) const
}
std::pair<double, double> LoadILLSANS::calculateQMaxQMin(){
double min=0, max=0;
double min= std::numeric_limits<double>::max(), max= std::numeric_limits<double>::min();
g_log.debug("Calculating Qmin Qmax...");
std::size_t nHist = m_localWorkspace->getNumberHistograms();
for (std::size_t i=0; i < nHist; ++i){
const MantidVec& lambdaBinning = m_localWorkspace->readX(i);
Geometry::IDetector_const_sptr det = m_localWorkspace->getDetector(i);
Kernel::V3D detPos = det->getPos();
double r, theta, phi;
detPos.getSpherical(r, theta, phi);
double v1 = calculateQ(*(lambdaBinning.begin()),theta);
double v2 = calculateQ(*(lambdaBinning.end()-1),theta);
//std::cout << "i=" << i << " theta="<<theta << " lambda_i=" << *(lambdaBinning.begin()) << " lambda_f=" << *(lambdaBinning.end()-1) << " v1=" << v1 << " v2=" << v2 << std::endl;
if ( i == 0) {
min = v1;
max = v1;
}
if (v1 < min){
min = v1;
}
if (v2 < min){
min = v2;
}
if (v1 > max){
max = v1;
}
if (v2 > max){
max = v2;
if ( ! det->isMonitor() ){
const MantidVec& lambdaBinning = m_localWorkspace->readX(i);
Kernel::V3D detPos = det->getPos();
double r, theta, phi;
detPos.getSpherical(r, theta, phi);
double v1 = calculateQ(*(lambdaBinning.begin()),theta);
double v2 = calculateQ(*(lambdaBinning.end()-1),theta);
//std::cout << "i=" << i << " theta="<<theta << " lambda_i=" << *(lambdaBinning.begin()) << " lambda_f=" << *(lambdaBinning.end()-1) << " v1=" << v1 << " v2=" << v2 << std::endl;
if ( i == 0) {
min = v1;
max = v1;
}
if (v1 < min){
min = v1;
}
if (v2 < min){
min = v2;
}
if (v1 > max){
max = v1;
}
if (v2 > max){
max = v2;
}
}
else
g_log.debug() << "Detector " << i << " is a Monitor : " << det->getID() << std::endl;
}
g_log.debug() << "Calculating Qmin Qmax. Done : [" << min << "," << max <<"]"<< std::endl;
......
......@@ -21,7 +21,8 @@ public:
}
LoadILLSANSTest() :
m_testFile("ILLD33_001030.nxs") {
m_testFileTof("ILLD33_001030.nxs"),
m_testFileNonTof("ILLD33_041714_NonTof.nxs"){
}
void testName() {
LoadILLSANS alg;
......@@ -39,10 +40,10 @@ public:
TS_ASSERT(alg.isInitialized())
}
void test_exec() {
void test_exec_TOF() {
LoadILLSANS loader;
loader.initialize();
loader.setPropertyValue("Filename", m_testFile);
loader.setPropertyValue("Filename", m_testFileTof);
std::string outputSpace = "LoadILLSANSTest_out";
loader.setPropertyValue("OutputWorkspace", outputSpace);
......@@ -56,14 +57,37 @@ public:
MatrixWorkspace_sptr output2D = boost::dynamic_pointer_cast<
MatrixWorkspace>(output);
TS_ASSERT_EQUALS(output2D->getNumberHistograms(), 65536);
TS_ASSERT_EQUALS(output2D->getNumberHistograms(), 65536+2);
TS_ASSERT_EQUALS(output2D->blocksize(), 100);
AnalysisDataService::Instance().clear();
}
void test_exec_nonTOF() {
LoadILLSANS loader;
loader.initialize();
loader.setPropertyValue("Filename", m_testFileNonTof);
std::string outputSpace = "LoadILLSANSTest_out";
loader.setPropertyValue("OutputWorkspace", outputSpace);
TS_ASSERT_THROWS_NOTHING(loader.execute());
// test workspace, copied from LoadMuonNexusTest.h
MatrixWorkspace_sptr output;
(output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(
outputSpace));
MatrixWorkspace_sptr output2D = boost::dynamic_pointer_cast<
MatrixWorkspace>(output);
TS_ASSERT_EQUALS(output2D->getNumberHistograms(), 65536+2);
TS_ASSERT_EQUALS(output2D->blocksize(), 1);
AnalysisDataService::Instance().clear();
}
private:
std::string m_testFile;
std::string m_testFileTof;
std::string m_testFileNonTof;
};
......
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