void LoadLLB::loadTimeDetails(NeXus::NXEntry &entry) { m_wavelength = entry.getFloat("nxbeam/incident_wavelength"); // Apparently this is in the wrong units // http://iramis.cea.fr/Phocea/file.php?class=page&reload=1227895533&file=21/How_to_install_and_use_the_Fitmib_suite_v28112008.pdf m_channelWidth = entry.getInt("nxmonitor/channel_width") * 0.1; g_log.debug("Nexus Data:"); g_log.debug() << " ChannelWidth: " << m_channelWidth << '\n'; g_log.debug() << " Wavelength: " << m_wavelength << '\n'; }
/** * Load data found in nexus file * * @param entry :: The Nexus entry * @param monitorsData :: Monitors data already loaded * */ void LoadILLReflectometry::loadDataIntoTheWorkSpace( NeXus::NXEntry &entry, std::vector<std::vector<int>> monitorsData) { m_wavelength = entry.getFloat("wavelength"); double ei = m_loader.calculateEnergy(m_wavelength); m_localWorkspace->mutableRun().addProperty<double>("Ei", ei, true); // overwrite // read in the data NXData dataGroup = entry.openNXData("data"); NXInt data = dataGroup.openIntData(); // load the counts from the file into memory data.load(); // Assign calculated bins to first X axis //// m_localWorkspace->dataX(0).assign(detectorTofBins.begin(), /// detectorTofBins.end()); size_t spec = 0; size_t nb_monitors = monitorsData.size(); Progress progress(this, 0, 1, m_numberOfTubes * m_numberOfPixelsPerTube + nb_monitors); // Assign tof values to first X axis // 1) Get some parameters from nexus file and properties // Note : This should be changed following future D17/ILL nexus file // improvement. const std::string propTOF0 = "monitor1.time_of_flight_0"; auto tof_channel_width_prop = dynamic_cast<PropertyWithValue<double> *>( m_localWorkspace->run().getProperty(propTOF0)); if (!tof_channel_width_prop) throw std::runtime_error("Could not cast (interpret) the property " + propTOF0 + " (channel width) as a floating point " "value."); m_channelWidth = *tof_channel_width_prop; /* PAR1[95] */ const std::string propTOF2 = "monitor1.time_of_flight_2"; auto tof_delay_prop = dynamic_cast<PropertyWithValue<double> *>( m_localWorkspace->run().getProperty(propTOF2)); if (!tof_delay_prop) throw std::runtime_error("Could not cast (interpret) the property " + propTOF2 + " (ToF delay) as a floating point value."); double tof_delay = *tof_delay_prop; /* PAR1[96] */ double POFF = entry.getFloat("instrument/VirtualChopper/poff"); /* par1[54] */ double open_offset = entry.getFloat("instrument/VirtualChopper/open_offset"); /* par1[56] */ double mean_chop_1_phase = 0.0; double mean_chop_2_phase = 0.0; // [30/09/14] Test on availability of VirtualChopper data double chop1_speed = entry.getFloat( "instrument/VirtualChopper/chopper1_speed_average"); /* PAR2[109] */ if (chop1_speed != 0.0) { // Virtual Chopper entries are valid // double mean_chop_1_phase = // entry.getFloat("instrument/VirtualChopper/chopper1_phase_average"); /* // PAR2[110] */ // this entry seems to be wrong for now, we use the old one instead [YR // 5/06/2014] mean_chop_1_phase = entry.getFloat("instrument/Chopper1/phase"); mean_chop_2_phase = entry.getFloat( "instrument/VirtualChopper/chopper2_phase_average"); /* PAR2[114] */ } else { // Use Chopper values instead chop1_speed = entry.getFloat("instrument/Chopper1/rotation_speed"); /* PAR2[109] */ mean_chop_1_phase = entry.getFloat("instrument/Chopper1/phase"); mean_chop_2_phase = entry.getFloat("instrument/Chopper2/phase"); } g_log.debug() << "m_numberOfChannels: " << m_numberOfChannels << std::endl; g_log.debug() << "m_channelWidth: " << m_channelWidth << std::endl; g_log.debug() << "tof_delay: " << tof_delay << std::endl; g_log.debug() << "POFF: " << POFF << std::endl; g_log.debug() << "open_offset: " << open_offset << std::endl; g_log.debug() << "mean_chop_2_phase: " << mean_chop_2_phase << std::endl; g_log.debug() << "mean_chop_1_phase: " << mean_chop_1_phase << std::endl; g_log.debug() << "chop1_speed: " << chop1_speed << std::endl; double t_TOF2 = 0.0; if (chop1_speed == 0.0) { g_log.debug() << "Warning: chop1_speed is null." << std::endl; // stay with t_TOF2 to O.0 } else { // Thanks to Miguel Gonzales/ILL for this TOF formula t_TOF2 = -1.e6 * 60.0 * (POFF - 45.0 + mean_chop_2_phase - mean_chop_1_phase + open_offset) / (2.0 * 360 * chop1_speed); } g_log.debug() << "t_TOF2: " << t_TOF2 << std::endl; // 2) Compute tof values for (size_t timechannelnumber = 0; timechannelnumber <= m_numberOfChannels; ++timechannelnumber) { double t_TOF1 = (static_cast<int>(timechannelnumber) + 0.5) * m_channelWidth + tof_delay; m_localWorkspace->dataX(0)[timechannelnumber] = t_TOF1 + t_TOF2; } // Load monitors for (size_t im = 0; im < nb_monitors; im++) { if (im > 0) { m_localWorkspace->dataX(im) = m_localWorkspace->readX(0); } // Assign Y int *monitor_p = monitorsData[im].data(); m_localWorkspace->dataY(im) .assign(monitor_p, monitor_p + m_numberOfChannels); progress.report(); } // Then Tubes for (size_t i = 0; i < m_numberOfTubes; ++i) { for (size_t j = 0; j < m_numberOfPixelsPerTube; ++j) { // just copy the time binning axis to every spectra m_localWorkspace->dataX(spec + nb_monitors) = m_localWorkspace->readX(0); //// Assign Y int *data_p = &data(static_cast<int>(i), static_cast<int>(j), 0); m_localWorkspace->dataY(spec + nb_monitors) .assign(data_p, data_p + m_numberOfChannels); // Assign Error MantidVec &E = m_localWorkspace->dataE(spec + nb_monitors); std::transform(data_p, data_p + m_numberOfChannels, E.begin(), LoadHelper::calculateStandardError); ++spec; progress.report(); } } // for m_numberOfTubes } // LoadILLIndirect::loadDataIntoTheWorkSpace
/* * Loads metadata present in the nexus file */ void LoadILLSANS::loadMetaData(const NeXus::NXEntry &entry, const std::string &instrumentNamePath) { g_log.debug("Loading metadata..."); API::Run &runDetails = m_localWorkspace->mutableRun(); int runNum = entry.getInt("run_number"); std::string run_num = std::to_string(runNum); runDetails.addProperty("run_number", run_num); if (entry.getFloat("mode") == 0.0) { // Not TOF runDetails.addProperty<std::string>("tof_mode", "Non TOF"); } else { runDetails.addProperty<std::string>("tof_mode", "TOF"); } std::string desc = m_loader.getStringFromNexusPath(entry, "sample_description"); runDetails.addProperty("sample_description", desc); std::string start_time = entry.getString("start_time"); start_time = m_loader.dateTimeInIsoFormat(start_time); runDetails.addProperty("run_start", start_time); std::string end_time = entry.getString("end_time"); end_time = m_loader.dateTimeInIsoFormat(end_time); runDetails.addProperty("run_end", end_time); double duration = entry.getFloat("duration"); runDetails.addProperty("timer", duration); double wavelength = entry.getFloat(instrumentNamePath + "/selector/wavelength"); g_log.debug() << "Wavelength found in the nexus file: " << wavelength << '\n'; if (wavelength <= 0) { g_log.debug() << "Mode = " << entry.getFloat("mode") << '\n'; g_log.information("The wavelength present in the NeXus file <= 0."); if (entry.getFloat("mode") == 0.0) { // Not TOF throw std::runtime_error("Working in Non TOF mode and the wavelength in " "the file is <=0 !!! Check with the instrument " "scientist!"); } } else { double wavelengthRes = entry.getFloat(instrumentNamePath + "/selector/wavelength_res"); runDetails.addProperty<double>("wavelength", wavelength); double ei = m_loader.calculateEnergy(wavelength); runDetails.addProperty<double>("Ei", ei, true); // wavelength m_defaultBinning[0] = wavelength - wavelengthRes * wavelength * 0.01 / 2; m_defaultBinning[1] = wavelength + wavelengthRes * wavelength * 0.01 / 2; } // Put the detector distances: // std::string detectorPath(instrumentNamePath + "/detector"); // // Just for Sample - RearDetector // double sampleDetectorDistance = // m_loader.getDoubleFromNexusPath(entry,detectorPath + "/det2_calc"); // runDetails.addProperty("sample_detector_distance", // sampleDetectorDistance); }
void LoadILLSANS::initWorkSpace(NeXus::NXEntry &firstEntry, const std::string &instrumentPath) { g_log.debug("Fetching data..."); NXData dataGroup1 = firstEntry.openNXData("data1"); NXInt dataRear = dataGroup1.openIntData(); dataRear.load(); NXData dataGroup2 = firstEntry.openNXData("data2"); NXInt dataRight = dataGroup2.openIntData(); dataRight.load(); NXData dataGroup3 = firstEntry.openNXData("data3"); NXInt dataLeft = dataGroup3.openIntData(); dataLeft.load(); NXData dataGroup4 = firstEntry.openNXData("data4"); NXInt dataDown = dataGroup4.openIntData(); dataDown.load(); NXData dataGroup5 = firstEntry.openNXData("data5"); NXInt dataUp = dataGroup5.openIntData(); dataUp.load(); g_log.debug("Checking channel numbers..."); // check number of channels if (dataRear.dim2() != dataRight.dim2() && dataRight.dim2() != dataLeft.dim2() && dataLeft.dim2() != dataDown.dim2() && dataDown.dim2() != dataUp.dim2()) { throw std::runtime_error( "The time bins have not the same dimension for all the 5 detectors!"); } int numberOfHistograms = dataRear.dim0() * dataRear.dim1() + dataRight.dim0() * dataRight.dim1() + dataLeft.dim0() * dataLeft.dim1() + dataDown.dim0() * dataDown.dim1() + dataUp.dim0() * dataUp.dim1(); g_log.debug("Creating empty workspace..."); // TODO : Must put this 2 somewhere else: number of monitors! createEmptyWorkspace(numberOfHistograms + 2, dataRear.dim2()); loadMetaData(firstEntry, instrumentPath); std::vector<double> binningRear, binningRight, binningLeft, binningDown, binningUp; if (firstEntry.getFloat("mode") == 0.0) { // Not TOF g_log.debug("Getting default wavelength bins..."); binningRear = m_defaultBinning; binningRight = m_defaultBinning; binningLeft = m_defaultBinning; binningDown = m_defaultBinning; binningUp = m_defaultBinning; } else { g_log.debug("Getting wavelength bins from the nexus file..."); std::string binPathPrefix(instrumentPath + "/tof/tof_wavelength_detector"); binningRear = m_loader.getTimeBinningFromNexusPath(firstEntry, binPathPrefix + "1"); binningRight = m_loader.getTimeBinningFromNexusPath(firstEntry, binPathPrefix + "2"); binningLeft = m_loader.getTimeBinningFromNexusPath(firstEntry, binPathPrefix + "3"); binningDown = m_loader.getTimeBinningFromNexusPath(firstEntry, binPathPrefix + "4"); binningUp = m_loader.getTimeBinningFromNexusPath(firstEntry, binPathPrefix + "5"); } g_log.debug("Loading the data into the workspace..."); 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); }