20 std::shared_ptr<std::vector<uint32_t>>
const &event_id,
21 std::shared_ptr<std::vector<float>>
const &tevent_time_of_flight,
size_t numEvents,
22 size_t startAt, std::shared_ptr<std::vector<uint64_t>>
const &tevent_index,
23 std::shared_ptr<BankPulseTimes>
const &thisBankPulseTimes,
bool have_weight,
24 std::shared_ptr<std::vector<float>>
const &tevent_weight, detid_t min_event_id,
26 :
Task(), m_loader(m_loader), entry_name(
std::move(entry_name)),
27 pixelID_to_wi_vector(m_loader.pixelID_to_wi_vector), pixelID_to_wi_offset(m_loader.pixelID_to_wi_offset),
28 prog(prog), event_detid(event_id), event_time_of_flight(tevent_time_of_flight),
numEvents(
numEvents),
29 startAt(startAt), event_index(tevent_index), thisBankPulseTimes(thisBankPulseTimes), have_weight(have_weight),
30 event_weight(tevent_weight), m_min_detid(min_event_id), m_max_detid(max_event_id) {
35 std::stringstream msg;
37 throw std::runtime_error(msg.str());
48 const auto thisId =
static_cast<detid_t>((*event_detid)[i]);
49 if (!(thisId < m_min_detid || thisId >
m_max_detid))
56 const size_t numEventLists = outputWS.getNumberHistograms();
59 if (counts[pixelIndex] > 0) {
63 if (wi < numEventLists) {
64 outputWS.reserveEventListAt(wi, counts[pixelIndex]);
66 if ((wi % 20 == 0) && alg->getCancel())
80 double my_shortest_tof =
static_cast<double>(std::numeric_limits<uint32_t>::max()) * 0.1;
81 double my_longest_tof = 0.;
84 size_t my_discarded_events(0);
96 throw std::runtime_error(
"Event index is not sorted");
104 const bool compress = (alg->compressEvents);
109 const double TOF_MIN = alg->filter_tof_min;
110 const double TOF_MAX = alg->filter_tof_max;
111 const bool NO_TOF_FILTERING = !(alg->filter_tof_range);
114 std::vector<size_t> pulseROI;
115 if (alg->m_is_time_filtered) {
116 pulseROI =
thisBankPulseTimes->getPulseIndices(alg->filter_time_start, alg->filter_time_stop);
119 if (alg->filter_bad_pulses) {
121 pulseROI,
thisBankPulseTimes->getPulseIndices(alg->bad_pulses_timeroi->toTimeIntervals()));
127 for (
const auto &pulseIter : pulseIndexer) {
131 const auto periodIndex =
static_cast<size_t>(logPeriodNumber - 1);
134 for (std::size_t eventIndex = pulseIter.eventIndexStart; eventIndex < pulseIter.eventIndexStop; ++eventIndex) {
137 const detid_t &detId =
static_cast<detid_t>((*event_detid)[eventIndex]);
140 const auto tof =
static_cast<double>((*event_time_of_flight)[eventIndex]);
142 if ((NO_TOF_FILTERING) || ((tof - TOF_MIN) * (tof - TOF_MAX) <= 0.)) {
148 const auto weight =
static_cast<double>((*event_weight)[eventIndex]);
149 const double errorSq = weight * weight;
150 eventVector->emplace_back(tof, pulsetime, weight, errorSq);
152 ++my_discarded_events;
159 eventVector->emplace_back(std::move(tof), pulsetime);
161 ++my_discarded_events;
169 if (tof > my_longest_tof) {
170 my_longest_tof = tof;
172 if (tof < my_shortest_tof) {
173 my_shortest_tof = tof;
180 if (!usedDetIds[detidIndex])
181 usedDetIds[detidIndex] =
true;
187 if ((pulseIter.pulseIndex % 6000 == 0) && alg->getCancel())
192 const auto pulseSortingType =
203 if (wi < numEventLists) {
204 auto &el = outputWS.getSpectrum(wi);
206 el.setSortOrder(pulseSortingType);
209 el.compressEvents(alg->compressTolerance, &el);
216 <<
"monotonically increasing pulse times\n";
221 std::lock_guard<std::mutex> _lock(alg->m_tofMutex);
222 if (my_shortest_tof < alg->shortest_tof) {
223 alg->shortest_tof = my_shortest_tof;
225 if (my_longest_tof > alg->longest_tof) {
226 alg->longest_tof = my_longest_tof;
228 alg->bad_tofs += badTofs;
229 alg->discarded_events += my_discarded_events;
233 if (alg->getLogger().isDebug())
234 alg->getLogger().debug() <<
"Time to ProcessBankData " <<
entry_name <<
" " << timer <<
"\n";
254 std::stringstream msg;
255 msg <<
"Error finding workspace index; pixelID " << pixID <<
" with offset " <<
pixelID_to_wi_offset
257 throw std::runtime_error(msg.str());
bool getCancel() const
Returns the cancellation state.
Helper class for reporting progress from algorithms.
Helper class for LoadEventNexus that is specific to the current default loading code for NXevent_data...
std::vector< std::vector< std::vector< Mantid::Types::Event::TofEvent > * > > eventVectors
Vector where index = event_id; value = ptr to std::vector<TofEvent> in the event list.
bool precount
Do we pre-count the # of events in each pixel ID?
std::vector< std::vector< std::vector< Mantid::DataObjects::WeightedEvent > * > > weightedEventVectors
Vector where index = event_id; value = ptr to std::vector<WeightedEvent> in the event list.
EventWorkspaceCollection & m_ws
size_t getNumberHistograms() const
size_t getWorkspaceIndexFromPixelID(const detid_t pixID)
Get the workspace index for a given pixel ID.
std::shared_ptr< std::vector< uint64_t > const > event_index
vector of event index (length of # of pulses)
detid_t m_min_detid
Minimum pixel id (inclusive)
detid_t m_max_detid
Maximum pixel id (inclusive)
bool have_weight
Flag for simulated data.
DefaultEventLoader & m_loader
Algorithm being run.
std::shared_ptr< std::vector< float > const > event_weight
event weights array
std::string entry_name
NXS address to bank.
size_t startAt
index of the first event from event_index
detid_t pixelID_to_wi_offset
Offset in the pixelID_to_wi_vector to use.
std::shared_ptr< std::vector< float > const > event_time_of_flight
event TOF array
std::shared_ptr< std::vector< uint32_t > const > event_detid
event pixel ID array
const std::vector< size_t > & pixelID_to_wi_vector
Vector where (index = pixel ID+pixelID_to_wi_offset), value = workspace index)
API::Progress * prog
Progress reporting.
void preCountAndReserveMem()
std::shared_ptr< BankPulseTimes const > thisBankPulseTimes
Pulse times for this bank.
ProcessBankData(DefaultEventLoader &loader, const std::string &entry_name, API::Progress *prog, std::shared_ptr< std::vector< uint32_t > > const &event_id, std::shared_ptr< std::vector< float > > const &event_time_of_flight, size_t numEvents, size_t startAt, std::shared_ptr< std::vector< uint64_t > > const &event_index, std::shared_ptr< BankPulseTimes > const &thisBankPulseTimes, bool have_weight, std::shared_ptr< std::vector< float > > const &event_weight, detid_t min_event_id, detid_t max_event_id)
Constructor.
void run() override
Run the data processing FIXME/TODO - split run() into readable methods.
PulseIndexer contains information for mapping from pulse index/number to event index.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
A Task is a unit of work to be scheduled and run by a ThreadPool.
double m_cost
Cached computational cost for the thread.
A simple class that provides a wall-clock (not processor time) timer.
void reset()
Explicitly reset the timer.
std::size_t numEvents(Nexus::File &file, bool &hasTotalCounts, bool &oldNeXusFileNames, const std::string &prefix, const Nexus::NexusDescriptor &descriptor)
Get the number of events in the currently opened group.
std::vector< TYPE > calculate_intersection(const std::vector< TYPE > &left, const std::vector< TYPE > &right)
This calculates the intersection of two sorted vectors that represent regions of interest (ROI).
int32_t detid_t
Typedef for a detector ID.