Commit 3d56963f authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Move to new Event definition

parent 1beb34ea
......@@ -227,18 +227,21 @@ StatusCode AnalysisDUT::run(std::shared_ptr<Clipboard> clipboard) {
continue;
}
// Get the event:
auto event = clipboard->get_event();
// Discard tracks which are very close to the frame edges
if(fabs(track->timestamp() - clipboard->get_persistent("eventEnd")) < m_timeCutFrameEdge) {
if(fabs(track->timestamp() - event->end()) < m_timeCutFrameEdge) {
// Late edge - eventEnd points to the end of the frame`
LOG(DEBUG) << " - track close to end of readout frame: "
<< Units::display(fabs(track->timestamp() - clipboard->get_persistent("eventEnd")), {"us", "ns"})
<< " at " << Units::display(track->timestamp(), {"us"});
<< Units::display(fabs(track->timestamp() - event->end()), {"us", "ns"}) << " at "
<< Units::display(track->timestamp(), {"us"});
continue;
} else if(fabs(track->timestamp() - clipboard->get_persistent("eventStart")) < m_timeCutFrameEdge) {
} else if(fabs(track->timestamp() - event->start()) < m_timeCutFrameEdge) {
// Early edge - eventStart points to the beginning of the frame
LOG(DEBUG) << " - track close to start of readout frame: "
<< Units::display(fabs(track->timestamp() - clipboard->get_persistent("eventStart")), {"us", "ns"})
<< " at " << Units::display(track->timestamp(), {"us"});
<< Units::display(fabs(track->timestamp() - event->start()), {"us", "ns"}) << " at "
<< Units::display(track->timestamp(), {"us"});
continue;
}
......
......@@ -106,18 +106,21 @@ StatusCode AnalysisEfficiency::run(std::shared_ptr<Clipboard> clipboard) {
continue;
}
// Get the event:
auto event = clipboard->get_event();
// Discard tracks which are very close to the frame edges
if(fabs(track->timestamp() - clipboard->get_persistent("eventEnd")) < m_timeCutFrameEdge) {
if(fabs(track->timestamp() - event->end()) < m_timeCutFrameEdge) {
// Late edge - eventEnd points to the end of the frame`
LOG(DEBUG) << " - track close to end of readout frame: "
<< Units::display(fabs(track->timestamp() - clipboard->get_persistent("eventEnd")), {"us", "ns"})
<< " at " << Units::display(track->timestamp(), {"us"});
<< Units::display(fabs(track->timestamp() - event->end()), {"us", "ns"}) << " at "
<< Units::display(track->timestamp(), {"us"});
continue;
} else if(fabs(track->timestamp() - clipboard->get_persistent("eventStart")) < m_timeCutFrameEdge) {
} else if(fabs(track->timestamp() - event->start()) < m_timeCutFrameEdge) {
// Early edge - eventStart points to the beginning of the frame
LOG(DEBUG) << " - track close to start of readout frame: "
<< Units::display(fabs(track->timestamp() - clipboard->get_persistent("eventStart")), {"us", "ns"})
<< " at " << Units::display(track->timestamp(), {"us"});
<< Units::display(fabs(track->timestamp() - event->start()), {"us", "ns"}) << " at "
<< Units::display(track->timestamp(), {"us"});
continue;
}
......
......@@ -152,9 +152,7 @@ void EventLoaderATLASpix::initialise() {
StatusCode EventLoaderATLASpix::run(std::shared_ptr<Clipboard> clipboard) {
// Check if event frame is defined:
if(!clipboard->has_persistent("eventStart") || !clipboard->has_persistent("eventEnd")) {
throw ModuleError("Event not defined. Add Metronome module or Event reader defining the event.");
}
auto event = clipboard->get_event();
// If have reached the end of file, close it and exit program running
if(m_file.eof()) {
......@@ -163,8 +161,8 @@ StatusCode EventLoaderATLASpix::run(std::shared_ptr<Clipboard> clipboard) {
return StatusCode::Failure;
}
double start_time = clipboard->get_persistent("eventStart");
double end_time = clipboard->get_persistent("eventEnd");
double start_time = event->start();
double end_time = event->end();
bool busy_at_start = m_detectorBusy;
// Read pixel data
......
......@@ -115,9 +115,7 @@ StatusCode EventLoaderCLICpix::run(std::shared_ptr<Clipboard> clipboard) {
}
// Now set the event time so that the Timepix3 data is loaded correctly
clipboard->put_persistent("eventStart", shutterStartTime);
clipboard->put_persistent("eventEnd", shutterStopTime);
clipboard->put_persistent("eventLength", (shutterStopTime - shutterStartTime));
clipboard->put_event(std::make_shared<Event>(shutterStartTime, shutterStopTime));
LOG(TRACE) << "Loaded " << npixels << " pixels";
// Put the data on the clipboard
......
......@@ -293,9 +293,7 @@ StatusCode EventLoaderCLICpix2::run(std::shared_ptr<Clipboard> clipboard) {
// Store current frame time and the length of the event:
LOG(DEBUG) << "Event time: " << Units::display(shutterStartTime, {"ns", "us", "s"})
<< ", length: " << Units::display((shutterStopTime - shutterStartTime), {"ns", "us", "s"});
clipboard->put_persistent("eventStart", shutterStartTime);
clipboard->put_persistent("eventEnd", shutterStopTime);
clipboard->put_persistent("eventLength", (shutterStopTime - shutterStartTime));
clipboard->put_event(std::make_shared<Event>(shutterStartTime, shutterStopTime));
// Put the data on the clipboard
if(!pixels->empty()) {
......
......@@ -92,9 +92,7 @@ StatusCode EventLoaderEUDAQ::run(std::shared_ptr<Clipboard> clipboard) {
// Store event time on clipboard for subsequent modules
// FIXME assumes trigger in center of two Mimosa26 frames:
auto frame_length = Units::get(115.2, "us");
clipboard->put_persistent("eventStart", timestamp - frame_length);
clipboard->put_persistent("eventEnd", timestamp + frame_length);
clipboard->put_persistent("eventLength", 2 * frame_length);
clipboard->put_event(std::make_shared<Event>(timestamp - frame_length, timestamp + frame_length));
// Advance to next event if possible, otherwise end this run:
if(!reader->NextEvent()) {
......
......@@ -220,9 +220,7 @@ StatusCode EventLoaderTimepix3::run(std::shared_ptr<Clipboard> clipboard) {
// loading a fixed number of pixels (ie. 2000 at a time)
// Check if event frame is defined:
if(!clipboard->has_persistent("eventStart") || !clipboard->has_persistent("eventEnd")) {
throw ModuleError("Event not defined. Add Metronome module or Event reader defining the event.");
}
auto event = clipboard->get_event();
LOG(TRACE) << "== New event";
......@@ -256,7 +254,7 @@ StatusCode EventLoaderTimepix3::run(std::shared_ptr<Clipboard> clipboard) {
IFLOG(INFO) {
if(temporalSplit) {
LOG_PROGRESS(DEBUG, "tpx3_loader")
<< "Current time: " << Units::display(clipboard->get_persistent("eventStart"), {"s", "ms", "us", "ns"});
<< "Current time: " << Units::display(event->start(), {"s", "ms", "us", "ns"});
} else {
LOG_PROGRESS(DEBUG, "tpx3_loader") << "Current event: " << m_currentEvent;
}
......@@ -335,6 +333,7 @@ void EventLoaderTimepix3::loadCalibration(std::string path, char delim, std::vec
bool EventLoaderTimepix3::loadData(std::shared_ptr<Clipboard> clipboard, Pixels* devicedata, SpidrSignals* spidrData) {
std::string detectorID = m_detector->name();
auto event = clipboard->get_event();
bool extra = false; // temp
......@@ -419,8 +418,7 @@ bool EventLoaderTimepix3::loadData(std::shared_ptr<Clipboard> clipboard, Pixels*
// November 2018 test beam.)
if(!m_detector->isDUT()) {
if(temporalSplit) {
LOG(WARNING) << "Current time: "
<< Units::display(clipboard->get_persistent("eventStart"), {"s", "ms", "us", "ns"})
LOG(WARNING) << "Current time: " << Units::display(event->start(), {"s", "ms", "us", "ns"})
<< " detector " << detectorID << " "
<< "header == 0x0! (indicates power pulsing.) Ignoring this.";
} else {
......@@ -450,7 +448,7 @@ bool EventLoaderTimepix3::loadData(std::shared_ptr<Clipboard> clipboard, Pixels*
// (and rewind the file
// reader so that we start with this signal next event)
if(temporalSplit) {
if(timestamp > clipboard->get_persistent("eventEnd")) {
if(timestamp > event->end()) {
(*m_file_iterator)->seekg(-1 * static_cast<int>(sizeof(pixdata)), std::ios_base::cur);
LOG(TRACE) << "Signal has a time beyond the current event: " << Units::display(timestamp, "ns");
break;
......@@ -579,19 +577,19 @@ bool EventLoaderTimepix3::loadData(std::shared_ptr<Clipboard> clipboard, Pixels*
const double timestamp = static_cast<double>(time) / (4096. / 25.) + m_detector->timingOffset();
// Ignore pixel data if it is before the "eventStart" read from the clipboard storage:
if(temporalSplit && (timestamp < clipboard->get_persistent("eventStart"))) {
if(temporalSplit && (timestamp < event->end())) {
LOG(TRACE) << "Skipping pixel, is before event window (" << Units::display(timestamp, {"s", "us", "ns"})
<< " < " << Units::display(clipboard->get_persistent("eventStart"), {"s", "us", "ns"}) << ")";
<< " < " << Units::display(event->end(), {"s", "us", "ns"}) << ")";
continue;
}
// Stop looking at data if the pixel is after the current event window
// (and rewind the file reader so that we start with this pixel next event)
if(temporalSplit && (timestamp > clipboard->get_persistent("eventEnd"))) {
if(temporalSplit && (timestamp > event->end())) {
LOG(DEBUG) << "Stopping processing event, pixel is after "
"event window ("
<< Units::display(timestamp, {"s", "us", "ns"}) << " > "
<< Units::display(clipboard->get_persistent("eventEnd"), {"s", "us", "ns"}) << ")";
<< Units::display(event->end(), {"s", "us", "ns"}) << ")";
(*m_file_iterator)->seekg(-1 * static_cast<int>(sizeof(pixdata)), std::ios_base::cur);
break;
}
......
......@@ -19,13 +19,11 @@ void Metronome::initialise() {
StatusCode Metronome::run(std::shared_ptr<Clipboard> clipboard) {
// Set up the current event:
LOG(DEBUG) << "Defining event, time frame " << Units::display(m_eventStart, {"us", "ms", "s"}) << " to "
<< Units::display(m_eventEnd, {"us", "ms", "s"});
clipboard->put_event(std::make_shared<Event>(m_eventStart, m_eventEnd));
// Set up the clipboard persistent storage for the current event:
clipboard->put_persistent("eventStart", m_eventStart);
clipboard->put_persistent("eventEnd", m_eventEnd);
clipboard->put_persistent("eventLength", m_eventLength);
// Increment the current event's start and end times by the configured event length
m_eventStart = m_eventEnd;
m_eventEnd += m_eventLength;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment