25using namespace Kernel;
27using namespace DataObjects;
48 "Different instrument with different detector combinations");
50 const std::vector<std::string> exts{
".h5",
".nxs"};
52 "The name of the Nexus file to load");
55 "Optional: Name of entry (default csns)");
58 "Default true: load bank data, false: load monitor data.");
61 "Optional: A comma-separated list of bank/monitor to read");
64 "Optional: A comma-separated list of StartNo of T0 to read.");
66 "Optional: A comma-separated list of endNo of T0 to read.");
69 "Default false: load event data, true: load histogram data.");
72 "An output orkspace.");
74 const std::string grp1 =
"Bank/Monitor";
78 const std::string grp2 =
"FilterByPulse";
90 Types::Core::DateAndTime data;
93 std::map<std::string, std::string> entries =
m_file->getEntries();
94 if (entries.find(typeName) != entries.end())
96 m_file->readData(typeName, expTime);
98 throw std::runtime_error(
"No experiment time in the NXS file!");
101 data = Mantid::Types::Core::DateAndTime(expTime);
103 data = Mantid::Types::Core::DateAndTime(
"2100-12-31T00:00:00+08:00");
114 int firstModuleId(-1), secondModuleId(-1);
115 if (bankName ==
"bank3") {
118 }
else if (bankName ==
"bank2") {
121 }
else if (bankName ==
"bank1") {
126 std::vector<std::string> data;
128 m_file->openGroup(
"instrument",
"NXinstrument");
129 auto entries =
m_file->getEntries();
130 for (
const auto &it : entries) {
131 const auto &
name = it.first;
134 data.emplace_back(
name);
148 if (inputNames.size() == 0)
150 else if (inputNames.size() > 1) {
151 return std::all_of(inputNames.cbegin(), inputNames.cend(),
152 [](
const auto &
name) { return name.compare(0, 6,
"module") == 0; });
163 const std::vector<std::string> &inputNames) {
164 std::vector<std::string> data;
165 if (inst ==
"SANS" || inst ==
"MR")
166 data.push_back(
"module1");
167 else if (inst ==
"GPPD") {
168 for (
const auto &
name : inputNames) {
169 if (
name.compare(0, 4,
"bank") == 0)
172 data.push_back(
name);
184 std::vector<int64_t> _tmp;
185 std::vector<int64_t> pixelId;
187 m_file->openGroup(
"instrument",
"NXinstrument");
188 auto entries =
m_file->getEntries();
189 for (
const auto &
name : inputList) {
190 auto it = entries.find(
name);
191 if (it != entries.end()) {
192 m_file->openGroup(it->first, it->second);
193 m_file->readData(
"pixel_id", _tmp);
194 pixelId.insert(pixelId.end(), _tmp.begin(), _tmp.end());
198 sort(pixelId.begin(), pixelId.end());
210 std::vector<int>
tmp;
212 m_file->openGroup(
"instrument",
"NXinstrument");
213 auto entries =
m_file->getEntries();
214 for (
const auto &[
name, nodeType] : entries) {
215 if ((
name.compare(0, 6, typeName) == 0) || (
name.compare(0, 7, typeName) == 0)) {
224 std::vector<uint32_t> timeBin(
tmp.begin(),
tmp.end());
234 std::vector<int>
tmp;
235 std::vector<uint32_t> data;
237 m_file->openGroup(
"csns",
"NXentry");
238 m_file->openGroup(
"histogram_data",
"NXcollection");
239 auto entries =
m_file->getEntries();
240 for (
const auto &
name : inputList) {
241 auto it = entries.find(
name);
242 if (it != entries.end()) {
243 m_file->openGroup(it->first, it->second);
245 data.insert(data.end(),
tmp.begin(),
tmp.end());
262 size_t pidNums,
const std::vector<uint32_t> &histData) {
263 size_t timeNums = timeOfFlight.size();
268 std::copy(timeOfFlight.cbegin(), timeOfFlight.cend(), xRef.begin());
270 std::vector<double> err;
271 err.resize(histData.size());
272 std::transform(histData.cbegin(), histData.cend(), std::back_inserter(err),
273 [](
auto const &hist) { return sqrt(hist); });
275 auto it_start = histData.begin();
276 auto it_end = it_start + timeNums - 1;
278 auto it_err_start = err.begin();
279 auto it_err_end = it_err_start + timeNums - 1;
282 while (hist < pidNums) {
285 Y.assign(it_start, it_end);
286 E.assign(it_err_start, it_err_end);
287 it_start += (timeNums - 1);
288 it_end += (timeNums - 1);
289 it_err_start += (timeNums - 1);
290 it_err_end += (timeNums - 1);
291 auto toPass = Kernel::make_cow<HistogramData::HistogramX>(xRef);
305std::multimap<uint32_t, std::pair<float, int64_t>>
307 const std::vector<uint32_t> &endList,
const std::vector<int64_t> &pids) {
308 std::vector<int64_t> pid_tmp;
309 std::vector<int64_t> pidList;
310 std::vector<int64_t> t0_tmp;
311 std::vector<int64_t> t0List;
312 std::vector<float> tof_tmp;
313 std::vector<float> tofList;
314 std::pair<float, int64_t> tofPulse;
316 m_file->openGroup(
"event_data",
"NXcollection");
317 auto entries =
m_file->getEntries();
318 for (
auto const &
name : inputList) {
319 auto it = entries.find(
name);
320 if (it != entries.end()) {
321 m_file->openGroup(it->first, it->second);
322 m_file->readData(
"event_pulse_time", t0_tmp);
323 m_file->readData(
"event_pixel_id", pid_tmp);
324 m_file->readData(
"event_time_of_flight", tof_tmp);
325 if (startList.size() == 0) {
326 t0List.insert(t0List.end(), t0_tmp.begin(), t0_tmp.end());
327 pidList.insert(pidList.end(), pid_tmp.begin(), pid_tmp.end());
328 tofList.insert(tofList.end(), tof_tmp.begin(), tof_tmp.end());
330 for (
size_t k = 0; k < t0_tmp.size(); k++) {
331 for (
size_t j = 0; j < startList.size(); j++) {
332 if (t0_tmp[k] >= startList[j] && t0_tmp[k] <= endList[j]) {
333 t0List.push_back(t0_tmp[k]);
334 pidList.push_back(pid_tmp[k]);
335 tofList.push_back(tof_tmp[k]);
348 std::map<int64_t, uint32_t> mapping;
350 for (
const auto &pidNum : pids) {
351 mapping.insert(std::map<int64_t, uint32_t>::value_type(pidNum, p));
354 std::multimap<uint32_t, std::pair<float, int64_t>> data;
355 for (
size_t i = 0; i < pidList.size(); i++) {
356 uint32_t specNo = mapping[pidList[i]];
357 tofPulse = std::make_pair(tofList[i], t0List[i]);
358 data.insert(std::multimap<uint32_t, std::pair<float, int64_t>>::value_type(specNo, tofPulse));
375 size_t pidNums,
const std::multimap<uint32_t, std::pair<float, int64_t>> &evtData) {
378 uint64_t m_pulseTime;
379 int endNum =
static_cast<int>(pidNums);
380 for (
auto i = 0; i != endNum; i++) {
381 auto it = evtData.find(i);
382 if (it != evtData.end()) {
383 for (
size_t j = 0; j != evtData.count(i); j++, it++) {
384 m_pulseTime = it->second.second;
385 m_tof = it->second.first;
386 workspace->getSpectrum(i) += Types::Event::TofEvent(m_tof, m_pulseTime);
388 workspace->getSpectrum(i).setSpectrumNo(i);
391 double dataMin = *(timeOfFlight.begin());
392 double dataMax = *(timeOfFlight.end() - 1);
393 workspace->setAllX(HistogramData::BinEdges{dataMin, dataMax});
402 const std::vector<std::string> bankNames =
getProperty(
"Bankname");
403 m_file = std::make_unique<::NeXus::File>(m_filename, NXACC_READ);
419 std::vector<uint32_t> tof_bank =
getTimeBin(
"module");
423 std::vector<uint32_t> startT0 =
getProperty(
"startT0");
424 std::vector<uint32_t> endT0 =
getProperty(
"endT0");
425 std::multimap<uint32_t, std::pair<float, int64_t>> evtData =
getEventData(
m_modules, startT0, endT0, pid_bank);
427 ws_evt->mutableRun().setStartAndEndTime(start_time, end_time);
429 ws_evt->setYUnit(
"Counts");
436 loadHistData(ws_hist, tof_bank, pid_bank.size(), histData);
437 ws_hist->mutableRun().setStartAndEndTime(start_time, end_time);
439 ws_hist->setYUnit(
"Counts");
442 throw std::runtime_error(
"Error in Banknames input!");
447 std::vector<int64_t> pid_mon =
getPixelId(bankNames);
448 std::vector<uint32_t> tof_mon =
getTimeBin(
"monitor");
450 std::vector<uint32_t> histData_mon =
getHistData(bankNames);
451 loadHistData(ws_hist, tof_mon, pid_mon.size(), histData_mon);
452 ws_hist->mutableRun().setStartAndEndTime(start_time, end_time);
454 ws_hist->setYUnit(
"Counts");
#define DECLARE_ALGORITHM(classname)
IPeaksWorkspace_sptr workspace
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.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
@ Load
allowed here which will be passed to the algorithm
A property class for workspaces.
LoadCSNSNexus : TODO: DESCRIPTION.
void loadHistData(API::MatrixWorkspace_sptr &workspace, const std::vector< uint32_t > &timeOfFlight, size_t pidNums, const std::vector< uint32_t > &histData)
load histogram data into workspace
std::vector< uint32_t > getTimeBin(const std::string &typeName)
Return time-of-flight.
std::vector< std::string > m_modules
std::vector< uint32_t > getHistData(const std::vector< std::string > &inputList)
Get histogram data.
const std::string category() const override
Algorithm's category for identification.
void exec() override
Execute the algorithm.
void init() override
Initialize the algorithm's properties.
std::multimap< uint32_t, std::pair< float, int64_t > > getEventData(const std::vector< std::string > &inputList, const std::vector< uint32_t > &startList, const std::vector< uint32_t > &endList, const std::vector< int64_t > &pids)
Get event data.
std::unique_ptr<::NeXus::File > m_file
int version() const override
Algorithm's version for identification.
Types::Core::DateAndTime getExperimentTime(const std::string &typeName)
Return the start or end time of experiment.
void loadEventData(DataObjects::EventWorkspace_sptr &workspace, const std::vector< uint32_t > &timeOfFlight, size_t pidNums, const std::multimap< uint32_t, std::pair< float, int64_t > > &evtData)
load event data into workspace
bool checkBanknames(const std::vector< std::string > &inputNames)
Judge the input of Bankname.
const std::string name() const override
Empty default constructor.
std::vector< int64_t > getPixelId(const std::vector< std::string > &inputList)
Return pixel id.
std::vector< std::string > getModules(const std::string &inst, const std::vector< std::string > &inputNames)
Return modules for special instrument.
std::vector< std::string > getGPPDModules(const std::string &bankName)
Return modules for special bankName at GPPD.
This class is intended to fulfill the design specified in <https://github.com/mantidproject/documents...
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void setPropertyGroup(const std::string &name, const std::string &group)
Set the group for a given property.
The Logger class is in charge of the publishing messages from the framework through various channels.
void information(const std::string &msg)
Logs at information level.
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Implements a copy on write data template.
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
@ Output
An output workspace.