15#include <boost/tokenizer.hpp>
25using Mantid::Types::Event::TofEvent;
69 "The name of the text file to read, including its full or "
70 "relative path. The file extension must be .dat.");
73 "The name of the text file to read, including its full or "
74 "relative path. The file extension must be meta.dat.");
77 "The name to use for the output workspace");
84 m_ws = std::make_shared<Mantid::DataObjects::EventWorkspace>();
88 std::map<uint32_t, std::vector<uint32_t>> eventMap =
loadData();
125 std::string componentName =
m_ws->getInstrument()->getStringParameter(
"detector-name")[0];
126 const double distance =
static_cast<double>(
m_ws->getInstrument()->getNumberParameter(
"detector-sample-distance")[0]);
128 const double angle = -
m_ws->run().getPropertyValueAsType<
double>(
"angle");
130 g_log.
information() <<
"Moving detector " << componentName <<
" " << distance <<
" meters and " << angle
133 constexpr double deg2rad = M_PI / 180.0;
135 double angle_rad = angle *
deg2rad;
136 V3D newpos(distance * sin(angle_rad), pos.
Y(), distance * cos(angle_rad));
140 constexpr V3D axis(0.0, 1.0, 0.0);
154 std::ifstream input(filename, std::ifstream::binary | std::ios::ate);
159 std::map<uint32_t, std::vector<uint32_t>> eventMap;
161 while (input.is_open()) {
165 input.read(
reinterpret_cast<char *
>(&tof),
sizeof(tof));
166 tof -=
static_cast<uint32_t
>(1e9);
167 tof =
static_cast<uint32_t
>(tof * 0.1);
170 input.read(
reinterpret_cast<char *
>(&pos),
sizeof(pos));
172 g_log.
warning() <<
"Detector index invalid: " << pos <<
'\n';
176 eventMap[pos].emplace_back(tof);
187 std::vector<double> metadata;
189 std::ifstream infile(filename);
191 g_log.
error(
"Error reading file " + filename);
195 while (getline(infile, line)) {
197 if (!line.empty() && line[0] !=
'#') {
198 g_log.
debug() <<
"Metadata parsed line: " << line <<
'\n';
203 [](
const auto &token) { return boost::lexical_cast<double>(token); });
206 if (metadata.size() < 6) {
207 g_log.
error(
"Expecting length >=6 for metadata arguments!");
224 runDetails.
addProperty<
double>(
"wavelength", metadata[1]);
225 runDetails.
addProperty<
double>(
"angle", metadata[5]);
233 for (
const auto &
position : eventMap) {
237 for (
const auto &event :
position.second) {
250 const unsigned int shortest_tof =
251 static_cast<unsigned int>(
m_ws->getInstrument()->getNumberParameter(
"shortest-tof")[0]);
252 const unsigned int longest_tof =
253 static_cast<unsigned int>(
m_ws->getInstrument()->getNumberParameter(
"longest-tof")[0]);
255 auto axis = HistogramData::BinEdges{
static_cast<double>(shortest_tof),
static_cast<double>(longest_tof)};
264 const unsigned int x_size =
265 static_cast<unsigned int>(
m_ws->getInstrument()->getNumberParameter(
"number-of-x-pixels")[0]);
266 const unsigned int y_size =
267 static_cast<unsigned int>(
m_ws->getInstrument()->getNumberParameter(
"number-of-y-pixels")[0]);
268 return x_size * y_size;
#define DECLARE_ALGORITHM(classname)
Mantid::Kernel::Quat(ComponentInfo::* rotation)(const size_t) const
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
@ Load
allowed here which will be passed to the algorithm
void setDetectorID(const detid_t detID)
Clear the list of detector IDs, then add one.
void setSpectrumNo(specnum_t num)
Sets the the spectrum number of this spectrum.
void addProperty(Kernel::Property *prop, bool overwrite=false)
Add data to the object in the form of a property.
This class stores information regarding an experimental run as a series of log entries.
A property class for workspaces.
LoadSwans : Test Loader to read data from the LDRD new SWANS detector.
void exec() override
Execute the algorithm.
const std::string m_instrumentName
void init() override
Initialize the algorithm's properties.
const std::string category() const override
Algorithm's category for identification.
const std::string name() const override
Algorithms name for identification.
void loadDataIntoTheWorkspace(const std::map< uint32_t, std::vector< uint32_t > > &eventMap)
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
unsigned int getDetectorSize()
From the Parameters XML file gets number-of-x-pixels and number-of-y-pixels and calculates the detect...
unsigned int m_detector_size
std::map< uint32_t, std::vector< uint32_t > > loadData()
Load the data into a map.
void placeDetectorInSpace()
Place the detector in space according to the distance and angle Needs in the IDF Parameters file the ...
int version() const override
Algorithm's version for identification.
void setMetaDataAsWorkspaceProperties(const std::vector< double > &metadata)
DataObjects::EventWorkspace_sptr m_ws
std::vector< double > loadMetaData()
Load metadata file witch to date is just a line of of double values Parses this file and put it into ...
void loadInstrument()
Run the Child Algorithm LoadInstrument.
void setTimeAxis()
Get shortest and longest tof from the Parameters file and sets the time axis Properties must be prese...
int confidence(Kernel::FileDescriptor &descriptor) const override
Returns a confidence value that this algorithm can load a file.
void addEventQuickly(const Types::Event::TofEvent &event)
Append an event to the histogram, without clearing the cache, to make it faster.
Records the filename and the description of failure.
Exception for when an item is not found in a collection.
Defines a wrapper around an open file.
const std::string & extension() const
Access the file extension.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
OptionalBool : Tri-state bool.
@ TOK_IGNORE_EMPTY
ignore empty tokens
@ TOK_TRIM
remove leading and trailing whitespace from tokens
std::size_t size() const noexcept
Get the total number of tokens.
ConstIterator cend() const
Const iterator referring to the past-the-end element in the container.
ConstIterator cbegin() const
Const iterator referring to first element in the container.
constexpr double Y() const noexcept
Get y.
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
void rotateComponent(const API::MatrixWorkspace_sptr &ws, const std::string &componentName, const Kernel::Quat &rot)
LoadHelper::rotateComponent.
void moveComponent(const API::MatrixWorkspace_sptr &ws, const std::string &componentName, const Kernel::V3D &newPos)
LoadHelper::moveComponent.
Kernel::V3D getComponentPosition(const API::MatrixWorkspace_sptr &ws, const std::string &componentName)
LoadHelper::getComponentPosition.
constexpr double deg2rad
Defines units/enum for Crystal work.
@ Output
An output workspace.