Skip to content

Commit

Permalink
Use raw file positions for simulation workspace. Refs #5797
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Aug 24, 2012
1 parent 21ed5c8 commit 3355884
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ namespace Mantid
MantidVecPtr createBinBoundaries() const;
/// Apply the created mapping to the workspace
void applyDetectorMapping();
/// Apply any instrument adjustments from the file
void adjustInstrument(const std::string & filename);

/// Pointer to a progress object
boost::shared_ptr<API::Progress> m_progress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,24 @@ namespace Mantid
m_outputWS->getAxis(0)->setUnit(getProperty("UnitX"));
m_outputWS->setYUnit("SpectraNumber");

m_progress = boost::shared_ptr<Progress>(new Progress(this,0.5, 1.0, nhistograms));
m_progress = boost::shared_ptr<Progress>(new Progress(this,0.5, 0.75, nhistograms));

PARALLEL_FOR1(m_outputWS)
for(int64_t i = 0; i < static_cast<int64_t>(nhistograms); ++i)
{
m_outputWS->setX(i, binBoundaries);
m_progress->report("Setting X values");
}

applyDetectorMapping();


// Update the instrument from the file if necessary
const std::string detTableFile = getProperty("DetectorTableFilename");
if(boost::algorithm::ends_with(detTableFile, ".raw") || boost::algorithm::ends_with(detTableFile, ".RAW") ||
boost::algorithm::ends_with(detTableFile, ".nxs") || boost::algorithm::ends_with(detTableFile, ".NXS"))
{
adjustInstrument(detTableFile);
}
}

/**
Expand Down Expand Up @@ -302,7 +310,41 @@ namespace Mantid
spectrum->addDetectorIDs(iter->second);
++wsIndex;
}
m_outputWS->generateSpectraMap();
}

/**
* Apply any instrument adjustments from the file
* @param filename :: The file to take the positions
*/
void CreateSimulationWorkspace::adjustInstrument(const std::string & filename)
{
// If requested update the instrument to positions in the raw file
const Geometry::ParameterMap & pmap = m_outputWS->instrumentParameters();
Geometry::Instrument_const_sptr instrument = m_outputWS->getInstrument();
boost::shared_ptr<Geometry::Parameter> updateDets = pmap.get(instrument->getComponentID(),"det-pos-source");
if(!updateDets) return; // No tag, use IDF

std::string value = updateDets->value<std::string>();
if(value.substr(0,8) == "datafile" )
{
IAlgorithm_sptr updateInst = createSubAlgorithm("UpdateInstrumentFromFile",0.75,1.0);
updateInst->setProperty<MatrixWorkspace_sptr>("Workspace", m_outputWS);
updateInst->setPropertyValue("Filename", filename);
if(value == "datafile-ignore-phi" )
{
updateInst->setProperty("IgnorePhi", true);
g_log.information("Detector positions in IDF updated with positions in the data file except for the phi values");
}
else
{
g_log.information("Detector positions in IDF updated with positions in the data file");
}
// We want this to throw if it fails to warn the user that the information is not correct.
updateInst->execute();
}
}


} // namespace DataHandling
} // namespace Mantid

0 comments on commit 3355884

Please sign in to comment.