Mantid
Loading...
Searching...
No Matches
LoadNGEM.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
11#include "MantidDataHandling/DllConfig.h"
13
14namespace Mantid {
15namespace DataHandling {
16
17static constexpr uint64_t CONTIN_ID_VALUE = 0x4F;
18static constexpr uint64_t EVENT_ID_MASK = 0x40;
19
22 uint64_t t0id : 24; // T0 ID
23 uint64_t reserved2 : 32; // Reserved for non-generics
24 uint64_t contin : 8; // 0x4F Continuation Code
25 uint64_t reserved1 : 56; // Reserved for non-generics
26 uint64_t id : 8; // Event ID
27 bool check() const {
28 // as id is 8 bit, we can do a simple AND to check
29 return (id & EVENT_ID_MASK) != 0 && contin == CONTIN_ID_VALUE;
30 }
31};
32
35 uint64_t t0id : 24; // T0 ID
36 uint64_t eventCount : 32; // Event Count
37 uint64_t contin : 8; // 0x4F Continuation Code
38 uint64_t totalLoss : 24; // Total loss count
39 uint64_t eventLoss : 20; // Event loss count
40 uint64_t frameLoss : 12; // Frame loss count
41 uint64_t id : 8; // 0x4E Event ID
42 static constexpr int T0_IDENTIFIER = 0x4E;
43 bool check() const { return id == T0_IDENTIFIER && contin == CONTIN_ID_VALUE; }
44};
45
48 uint64_t t0id : 24; // T0 ID
49 uint64_t clusterTimeY : 10; // Integrated time of the cluster on the Y side
50 // (5ns pixel)
51 uint64_t timeDiffY : 6; // Time lag from first to last detection on Y (5ns)
52 uint64_t clusterTimeX : 10; // Integrated time of the cluster on the X side
53 // (5ns pixel)
54 uint64_t timeDiffX : 6; // Time lag from first to last detection on X (5ns)
55 uint64_t contin : 8; // 0x4F Continuation Code
56 uint64_t lastY : 7; // Y position of pixel detected last
57 uint64_t firstY : 7; // Y position of pixel detected first
58 uint64_t lastX : 7; // X position of pixel detected last
59 uint64_t firstX : 7; // X position of pixel detected first
60 uint64_t timeOfFlight : 28; // Difference between T0 and detection (1ns)
61 uint64_t id : 8; // 0x47 Event ID.
62
63 uint64_t avgX() const { return (firstX + lastX) / 2; }
64 uint64_t avgY() const { return (firstY + lastY) / 2; }
65 static constexpr int COINCIDENCE_IDENTIFIER = 0x47;
66 bool check() { return id == COINCIDENCE_IDENTIFIER && contin == CONTIN_ID_VALUE; }
67 uint64_t getPixel() const {
68 return avgX() + (avgY() << 7); // Increase Y significance by 7 bits to
69 // account for 128x128 grid.
70 }
71};
72
75 uint64_t words[2]; // Array holding the word from the detector split in two.
76};
77
85
88 int rawFrames = 0;
89 int goodFrames = 0;
90 std::vector<double> frameEventCounts;
92};
93
95public:
96 virtual void addEvent(double &minToF, double &maxToF, const double tof, const double binWidth,
97 const size_t pixel) = 0;
98 virtual void addFrame(int &rawFrames, int &goodFrames, const int eventCountInFrame, const int minEventsReq,
99 const int maxEventsReq, MantidVec &frameEventCounts) = 0;
100};
101
103public:
104 LoadDataStrategyHisto(const double minToF, const double maxToF, const double binWidth);
105 void addEvent(double &minToF, double &maxToF, const double tof, const double binWidth, const size_t pixel) override;
106 void addFrame(int &rawFrames, int &goodFrames, const int eventCountInFrame, const int minEventsReq,
107 const int maxEventsReq, MantidVec &frameEventCounts) override;
108 inline std::vector<std::vector<double>> &getCounts() { return m_counts; }
109 inline std::vector<double> &getBinEdges() { return m_binEdges; }
110
111private:
112 std::vector<std::vector<double>> m_counts;
113 std::vector<std::vector<double>> m_countsInFrame;
114 std::vector<double> m_binEdges;
115};
116
118public:
120 void addEvent(double &minToF, double &maxToF, const double tof, const double binWidth, const size_t pixel) override;
121 void addFrame(int &rawFrames, int &goodFrames, const int eventCountInFrame, const int minEventsReq,
122 const int maxEventsReq, MantidVec &frameEventCounts) override;
123 inline std::vector<DataObjects::EventList> &getEvents() { return m_events; }
124
125private:
126 std::vector<DataObjects::EventList> m_events;
127 std::vector<DataObjects::EventList> m_eventsInFrame;
128};
129
130class MANTID_DATAHANDLING_DLL LoadNGEM : public API::IFileLoader<Kernel::FileDescriptor> {
131public:
133 const std::string name() const override { return "LoadNGEM"; }
135 const std::string summary() const override {
136 return "Load a file or range of files created by the nGEM detector into a "
137 "workspace.";
138 };
140 int version() const override { return 1; }
142 const std::string category() const override { return "DataHandling\\NGEM"; };
144 bool loadMutipleAsOne() override { return true; }
145
147 int confidence(Kernel::FileDescriptor &descriptor) const override;
148
149private:
150 int m_fileCount = 0;
152 void init() override;
154 void exec() override;
156 void loadSingleFile(const std::vector<std::string> &filePath, int &eventCountInFrame, double &minToF, double &maxToF,
157 const double binWidth, int &rawFrames, int &goodFrames, const int minEventsReq,
158 const int maxEventsReq, MantidVec &frameEventCounts, const size_t totalFilePaths,
159 std::shared_ptr<LoadDataStrategyBase> strategy);
161 size_t verifyFileSize(std::ifstream &file);
163 bool reportProgressAndCheckCancel(size_t &numProcessedEvents, int &eventCountInFrame, const size_t totalNumEvents,
164 const size_t totalFilePaths);
166 void createCountWorkspace(const std::vector<double> &frameEventCounts);
168 void loadInstrument(API::MatrixWorkspace_sptr &dataWorkspace);
170 std::map<std::string, std::string> validateInputs() override;
172 std::vector<std::pair<std::string, std::string>> validateEventsPerFrame();
174 std::vector<std::pair<std::string, std::string>> validateMinMaxToF();
176 LoadDataResult readDataAsHistograms(double &minToF, double &maxToF, const double binWidth, const int minEventsReq,
177 const int maxEventsReq, const std::vector<std::vector<std::string>> &filePaths);
179 LoadDataResult readDataAsEvents(double &minToF, double &maxToF, const double binWidth, const int minEventsReq,
180 const int maxEventsReq, const std::vector<std::vector<std::string>> &filePaths);
181};
182
183} // namespace DataHandling
184} // namespace Mantid
Defines an interface to an algorithm that loads a file so that it can take part in the automatic sele...
Definition IFileLoader.h:19
virtual void addEvent(double &minToF, double &maxToF, const double tof, const double binWidth, const size_t pixel)=0
virtual void addFrame(int &rawFrames, int &goodFrames, const int eventCountInFrame, const int minEventsReq, const int maxEventsReq, MantidVec &frameEventCounts)=0
void addFrame(int &rawFrames, int &goodFrames, const int eventCountInFrame, const int minEventsReq, const int maxEventsReq, MantidVec &frameEventCounts) override
Add a completed frame to the event list.
Definition LoadNGEM.cpp:696
std::vector< DataObjects::EventList > m_eventsInFrame
Definition LoadNGEM.h:127
std::vector< DataObjects::EventList > m_events
Definition LoadNGEM.h:126
std::vector< DataObjects::EventList > & getEvents()
Definition LoadNGEM.h:123
void addEvent(double &minToF, double &maxToF, const double tof, const double binWidth, const size_t pixel) override
Add an event to the event list.
Definition LoadNGEM.cpp:674
std::vector< std::vector< double > > & getCounts()
Definition LoadNGEM.h:108
std::vector< std::vector< double > > m_counts
Definition LoadNGEM.h:112
std::vector< double > & getBinEdges()
Definition LoadNGEM.h:109
std::vector< std::vector< double > > m_countsInFrame
Definition LoadNGEM.h:113
const std::string name() const override
Algorithm's name for identification.
Definition LoadNGEM.h:133
int version() const override
Algorithm's Version for identification.
Definition LoadNGEM.h:140
bool loadMutipleAsOne() override
Should the loader load multiple files into one workspace.
Definition LoadNGEM.h:144
const std::string summary() const override
The purpose of the algorithm.
Definition LoadNGEM.h:135
const std::string category() const override
Algorithm's category for identification.
Definition LoadNGEM.h:142
Defines a wrapper around an open file.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
static constexpr uint64_t CONTIN_ID_VALUE
Definition LoadNGEM.h:17
static constexpr uint64_t EVENT_ID_MASK
Definition LoadNGEM.h:18
Helper class which provides the Collimation Length for SANS instruments.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Definition cow_ptr.h:172
static constexpr int COINCIDENCE_IDENTIFIER
Definition LoadNGEM.h:65
Holds the 128 bit words from the detector.
Definition LoadNGEM.h:74
Generic event to separate bits.
Definition LoadNGEM.h:21
Holds variables tracking the data load across all files.
Definition LoadNGEM.h:87
API::MatrixWorkspace_sptr dataWorkspace
Definition LoadNGEM.h:91
std::vector< double > frameEventCounts
Definition LoadNGEM.h:90
Indicate time 0, the start of a new frame.
Definition LoadNGEM.h:34
static constexpr int T0_IDENTIFIER
Definition LoadNGEM.h:42
Is able to hold all versions of the data words in the same memory location.
Definition LoadNGEM.h:79
CoincidenceEvent coincidence
Definition LoadNGEM.h:82