From 152e426efb52221279966c82be9b6bce5e14722f Mon Sep 17 00:00:00 2001 From: Tibor Bukovics Date: Mon, 16 Sep 2024 16:40:39 +0000 Subject: [PATCH 1/8] set filtering accoridng to intensity and time --- src/modules/timepix3/handlers/PixelEventHandler.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/modules/timepix3/handlers/PixelEventHandler.cpp b/src/modules/timepix3/handlers/PixelEventHandler.cpp index b3da71794..cfc990af8 100644 --- a/src/modules/timepix3/handlers/PixelEventHandler.cpp +++ b/src/modules/timepix3/handlers/PixelEventHandler.cpp @@ -131,11 +131,20 @@ void PixelEventHandler::publishEvents(Cluster2DContainer &clusters) { // detector, it is the time the first photon in the cluster hit the // detector. - if (cluster.hitCount() < TimepixConfiguration.MinEventSizeHits) { + // if (cluster.hitCount() < TimepixConfiguration.MinEventSizeHits) { + // statCounters.ClusterSizeTooSmall++; + // continue; + // } + + if (cluster.weightSum() < TimepixConfiguration.MinEventSizeHits) { statCounters.ClusterSizeTooSmall++; continue; } + if (cluster.timeSpan() < 90) { + continue; + } + uint64_t eventTime = cluster.timeStart(); long eventTof = eventTime - lastEpochESSPulseTime->pulseTimeInEpochNs; statCounters.TofCount++; From 7209a62e8626c4ea34a61c3750d205a9741f9540 Mon Sep 17 00:00:00 2001 From: Tibor Bukovics Date: Mon, 16 Sep 2024 16:53:32 +0000 Subject: [PATCH 2/8] Add new cluster filtering --- src/modules/timepix3/geometry/Config.cpp | 9 ++++++++- src/modules/timepix3/geometry/Config.h | 4 +++- src/modules/timepix3/handlers/PixelEventHandler.cpp | 9 ++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/modules/timepix3/geometry/Config.cpp b/src/modules/timepix3/geometry/Config.cpp index 2d943959a..e363a4779 100644 --- a/src/modules/timepix3/geometry/Config.cpp +++ b/src/modules/timepix3/geometry/Config.cpp @@ -56,13 +56,20 @@ Config::Config(std::string ConfigFile) { XResolution, YResolution, ScaleUpFactor, XResolution * ScaleUpFactor, YResolution * ScaleUpFactor); } catch (...) { - LOG(INIT, Sev::Info, "Using default ScaleUpFactor = {}, super resolution not applied", ScaleUpFactor); + LOG(INIT, Sev::Info, + "Using default ScaleUpFactor = {}, super resolution not applied", + ScaleUpFactor); } try { MaxTimeGapNS = root["MaxTimeGapNS"].get(); } catch (...) { LOG(INIT, Sev::Info, "Using default MaxTimeGapNS = {}", MaxTimeGapNS); } + try { + MinEventTimeSpan = root["MinEventTimeSpanNS"].get(); + } catch (...) { + LOG(INIT, Sev::Info, "Using default MaxTimeGapNS = {}", MinEventTimeSpan); + } try { FrequencyHz = root["FrequencyHz"].get(); } catch (...) { diff --git a/src/modules/timepix3/geometry/Config.h b/src/modules/timepix3/geometry/Config.h index a5e73d1b6..83036665c 100644 --- a/src/modules/timepix3/geometry/Config.h +++ b/src/modules/timepix3/geometry/Config.h @@ -10,6 +10,7 @@ #pragma once #include +#include #include #include @@ -32,7 +33,8 @@ class Config { uint32_t MaxTimeGapNS{1}; uint32_t MinEventSizeHits{1}; - uint32_t MinimumToTSum{0}; + uint32_t MinimumToTSum{20}; + uint32_t MinEventTimeSpan{100}; uint16_t MaxCoordinateGap{5}; }; } // namespace Timepix3 diff --git a/src/modules/timepix3/handlers/PixelEventHandler.cpp b/src/modules/timepix3/handlers/PixelEventHandler.cpp index cfc990af8..dcc1ede27 100644 --- a/src/modules/timepix3/handlers/PixelEventHandler.cpp +++ b/src/modules/timepix3/handlers/PixelEventHandler.cpp @@ -131,17 +131,12 @@ void PixelEventHandler::publishEvents(Cluster2DContainer &clusters) { // detector, it is the time the first photon in the cluster hit the // detector. - // if (cluster.hitCount() < TimepixConfiguration.MinEventSizeHits) { - // statCounters.ClusterSizeTooSmall++; - // continue; - // } - - if (cluster.weightSum() < TimepixConfiguration.MinEventSizeHits) { + if (cluster.hitCount() < TimepixConfiguration.MinEventSizeHits || cluster.weightSum() < TimepixConfiguration.MinimumToTSum) { statCounters.ClusterSizeTooSmall++; continue; } - if (cluster.timeSpan() < 90) { + if (cluster.timeSpan() < TimepixConfiguration.MinEventTimeSpan) { continue; } From a949eeeb49d432271fb7e102f74ab36f4912c89a Mon Sep 17 00:00:00 2001 From: Tibor Bukovics Date: Mon, 16 Sep 2024 18:06:58 +0000 Subject: [PATCH 3/8] correct incorrect default value --- src/modules/timepix3/geometry/Config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/timepix3/geometry/Config.h b/src/modules/timepix3/geometry/Config.h index 83036665c..ae0bb3a58 100644 --- a/src/modules/timepix3/geometry/Config.h +++ b/src/modules/timepix3/geometry/Config.h @@ -34,7 +34,7 @@ class Config { uint32_t MaxTimeGapNS{1}; uint32_t MinEventSizeHits{1}; uint32_t MinimumToTSum{20}; - uint32_t MinEventTimeSpan{100}; + uint32_t MinEventTimeSpan{1}; uint16_t MaxCoordinateGap{5}; }; } // namespace Timepix3 From d1002b30808e4522be216266d3842e00bcc1a18a Mon Sep 17 00:00:00 2001 From: Tibor Bukovics Date: Tue, 17 Sep 2024 06:31:39 +0000 Subject: [PATCH 4/8] Test improved gap calculation --- .../clustering/Hierarchical2DClusterer.cpp | 24 +++++++++---------- .../clustering/Hierarchical2DClusterer.h | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/common/reduction/clustering/Hierarchical2DClusterer.cpp b/src/common/reduction/clustering/Hierarchical2DClusterer.cpp index 87e3eddb5..df8b22484 100644 --- a/src/common/reduction/clustering/Hierarchical2DClusterer.cpp +++ b/src/common/reduction/clustering/Hierarchical2DClusterer.cpp @@ -55,16 +55,16 @@ void Hierarchical2DClusterer::cluster_by_x() { continue; // skip points that have already been visited } XTRACE(DATA, DEB, "Starting new cluster"); - Hit2DVector space_cluster; // initialize a new cluster - space_cluster.push_back(current_time_cluster_[i]); + Cluster2D space_cluster; // initialize a new cluster + space_cluster.insert(current_time_cluster_[i]); visited[i] = true; for (uint j = i + 1; j < clusterSize; j++) { if (visited[j]) { continue; // skip points that have already been visited } - double x_distance = (double)current_time_cluster_[i].x_coordinate - + double x_distance = space_cluster.xCoordCenter() - (double)current_time_cluster_[j].x_coordinate; - double y_distance = (double)current_time_cluster_[i].y_coordinate - + double y_distance = space_cluster.yCoordCenter() - (double)current_time_cluster_[j].y_coordinate; // Calculate distance according to d^2 = dx^2 + dy^2 to remove sqrt calculation @@ -81,7 +81,7 @@ void Hierarchical2DClusterer::cluster_by_x() { // Compare with the squere of the max_coord_gap to save computation time on sqrt above if (distance_sqr < max_coord_gap_sqr_) { XTRACE(DATA, DEB, "Adding to existing cluster"); - space_cluster.push_back( + space_cluster.insert( current_time_cluster_[j]); // add point to current cluster visited[j] = true; } else { @@ -92,13 +92,13 @@ void Hierarchical2DClusterer::cluster_by_x() { } } -void Hierarchical2DClusterer::stash_cluster(Hit2DVector &xz_cluster) { - Cluster2D cluster; - for (const auto &hit : xz_cluster) { - cluster.insert(hit); - } - Abstract2DClusterer::stash_cluster(cluster); -} +// void Hierarchical2DClusterer::stash_cluster(Hit2DVector &xz_cluster) { +// Cluster2D cluster; +// for (const auto &hit : xz_cluster) { +// cluster.insert(hit); +// } +// Abstract2DClusterer::stash_cluster(cluster); +// } std::string Hierarchical2DClusterer::config(const std::string &prepend) const { std::stringstream ss; diff --git a/src/common/reduction/clustering/Hierarchical2DClusterer.h b/src/common/reduction/clustering/Hierarchical2DClusterer.h index cbe1b4aae..9149162b7 100644 --- a/src/common/reduction/clustering/Hierarchical2DClusterer.h +++ b/src/common/reduction/clustering/Hierarchical2DClusterer.h @@ -69,5 +69,5 @@ class Hierarchical2DClusterer : public Abstract2DClusterer { /// \brief helper function to clusters hits in current_time_cluster_ void cluster_by_x(); - void stash_cluster(Hit2DVector &xz_cluster); + // void stash_cluster(Hit2DVector &xz_cluster); }; From 3959c94c44886f3c303301af0e9b39c42b8648a2 Mon Sep 17 00:00:00 2001 From: Tibor Bukovics Date: Tue, 17 Sep 2024 07:23:16 +0000 Subject: [PATCH 5/8] trigger new build --- src/modules/timepix3/handlers/PixelEventHandler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/timepix3/handlers/PixelEventHandler.cpp b/src/modules/timepix3/handlers/PixelEventHandler.cpp index dcc1ede27..a6ddf0abf 100644 --- a/src/modules/timepix3/handlers/PixelEventHandler.cpp +++ b/src/modules/timepix3/handlers/PixelEventHandler.cpp @@ -135,6 +135,7 @@ void PixelEventHandler::publishEvents(Cluster2DContainer &clusters) { statCounters.ClusterSizeTooSmall++; continue; } + if (cluster.timeSpan() < TimepixConfiguration.MinEventTimeSpan) { continue; From 942c642b392536cc26c2e77ed90c6338a77a0a3a Mon Sep 17 00:00:00 2001 From: Tibor Bukovics Date: Wed, 18 Sep 2024 08:20:09 +0000 Subject: [PATCH 6/8] cleanup --- src/modules/timepix3/handlers/PixelEventHandler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/timepix3/handlers/PixelEventHandler.cpp b/src/modules/timepix3/handlers/PixelEventHandler.cpp index a6ddf0abf..1b7a01019 100644 --- a/src/modules/timepix3/handlers/PixelEventHandler.cpp +++ b/src/modules/timepix3/handlers/PixelEventHandler.cpp @@ -131,11 +131,11 @@ void PixelEventHandler::publishEvents(Cluster2DContainer &clusters) { // detector, it is the time the first photon in the cluster hit the // detector. - if (cluster.hitCount() < TimepixConfiguration.MinEventSizeHits || cluster.weightSum() < TimepixConfiguration.MinimumToTSum) { + if (cluster.hitCount() < TimepixConfiguration.MinEventSizeHits || + cluster.weightSum() < TimepixConfiguration.MinimumToTSum) { statCounters.ClusterSizeTooSmall++; continue; } - if (cluster.timeSpan() < TimepixConfiguration.MinEventTimeSpan) { continue; From 533a3871983a66cf93f6bf9c5446a4e9adfac0b3 Mon Sep 17 00:00:00 2001 From: Tibor Bukovics Date: Thu, 19 Sep 2024 07:26:00 +0000 Subject: [PATCH 7/8] trigger a build --- src/modules/timepix3/configs/timepix3.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/timepix3/configs/timepix3.json b/src/modules/timepix3/configs/timepix3.json index a6a4b501e..c9622ebf7 100644 --- a/src/modules/timepix3/configs/timepix3.json +++ b/src/modules/timepix3/configs/timepix3.json @@ -9,4 +9,4 @@ "MaxCoordinateGap": 4, "MinEventSizeHits": 9, "FrequencyHz": 10 -} \ No newline at end of file +} From ddff1d4dbcc41d6f9fe4b0cc00a6e0c725c91627 Mon Sep 17 00:00:00 2001 From: Tibor Bukovics Date: Mon, 30 Sep 2024 14:19:01 +0000 Subject: [PATCH 8/8] Normalize event, new counters --- src/modules/timepix3/Counters.h | 1 + src/modules/timepix3/Timepix3Base.cpp | 1 + .../timepix3/handlers/PixelEventHandler.cpp | 19 +++++---- .../test/Timepix3PixelEventHandlerTest.cpp | 40 +++++++++++++++---- 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/modules/timepix3/Counters.h b/src/modules/timepix3/Counters.h index 0f63399ca..166b28ddb 100644 --- a/src/modules/timepix3/Counters.h +++ b/src/modules/timepix3/Counters.h @@ -30,6 +30,7 @@ struct Counters { int64_t TofNegative{0}; int64_t PrevTofCount{0}; int64_t ClusterSizeTooSmall{0}; + int64_t ClusterToShort{0}; int64_t PixelReadouts{0}; int64_t InvalidPixelReadout{0}; diff --git a/src/modules/timepix3/Timepix3Base.cpp b/src/modules/timepix3/Timepix3Base.cpp index 836e39be2..a86fab64a 100644 --- a/src/modules/timepix3/Timepix3Base.cpp +++ b/src/modules/timepix3/Timepix3Base.cpp @@ -58,6 +58,7 @@ Timepix3Base::Timepix3Base(BaseSettings const &settings) Stats.create("handlers.pixelevent.tof_count", Counters.TofCount); Stats.create("handlers.pixelevent.tof_neg", Counters.TofNegative); Stats.create("handlers.pixelevent.cluster_size_to_small", Counters.ClusterSizeTooSmall); + Stats.create("handlers.pixelevent.cluster_to_short", Counters.ClusterToShort); Stats.create("handlers.pixelevent.prevtof_count", Counters.PrevTofCount); // Events diff --git a/src/modules/timepix3/handlers/PixelEventHandler.cpp b/src/modules/timepix3/handlers/PixelEventHandler.cpp index bd0ec85b5..917486e86 100644 --- a/src/modules/timepix3/handlers/PixelEventHandler.cpp +++ b/src/modules/timepix3/handlers/PixelEventHandler.cpp @@ -133,32 +133,37 @@ void PixelEventHandler::publishEvents(Cluster2DContainer &clusters) { if (cluster.hitCount() < TimepixConfiguration.MinEventSizeHits || cluster.weightSum() < TimepixConfiguration.MinimumToTSum) { - + statCounters.ClusterSizeTooSmall++; continue; } if (cluster.timeSpan() < TimepixConfiguration.MinEventTimeSpan) { + statCounters.ClusterToShort++; continue; } uint64_t eventTime = cluster.timeStart(); - long eventTof = eventTime - lastEpochESSPulseTime->pulseTimeInEpochNs; + long eventTofNs = eventTime - lastEpochESSPulseTime->pulseTimeInEpochNs; statCounters.TofCount++; - if (eventTof < 0) { + if (eventTofNs < 0) { statCounters.TofNegative++; continue; } - if (eventTof > FrequencyPeriodNs.count()) { + // If the event would be the next pulse, move it to the beginning of the + // current pulse to keep up statistics + if (eventTofNs > FrequencyPeriodNs.count()) { XTRACE(EVENT, WAR, "Event is for the next pulse, EventTime: %u, Current " "pulse time: %u, Difference: %u", - eventTime, lastEpochESSPulseTime->pulseTimeInEpochNs, eventTof); + eventTime, lastEpochESSPulseTime->pulseTimeInEpochNs, eventTofNs); statCounters.EventTimeForNextPulse++; - continue; + // Normalize the event time to the current pulse + eventTofNs = eventTofNs % FrequencyPeriodNs.count(); // Ensure eventTofNs is within the period } + double EventCoordX = cluster.xCoordCenter(); double EventCoordY = cluster.yCoordCenter(); uint32_t PixelId = geometry->calcPixelId(EventCoordX, EventCoordY); @@ -170,7 +175,7 @@ void PixelEventHandler::publishEvents(Cluster2DContainer &clusters) { continue; } XTRACE(EVENT, DEB, "New event, Time: %u, PixelId: %u", eventTime, PixelId); - serializer.addEvent(eventTof, PixelId); + serializer.addEvent(eventTofNs, PixelId); statCounters.Events++; } clusters.clear(); diff --git a/src/modules/timepix3/test/Timepix3PixelEventHandlerTest.cpp b/src/modules/timepix3/test/Timepix3PixelEventHandlerTest.cpp index fe2d6bec3..c30210156 100644 --- a/src/modules/timepix3/test/Timepix3PixelEventHandlerTest.cpp +++ b/src/modules/timepix3/test/Timepix3PixelEventHandlerTest.cpp @@ -4,9 +4,11 @@ /// \file //===----------------------------------------------------------------------===// +#include #include #include #include +#include #include #include #include @@ -50,12 +52,17 @@ class PixelTimeTestHelper { const uint64_t pixelClockTime; - PixelTimeTestHelper(int16_t ToA, uint8_t fToA) + PixelTimeTestHelper(uint16_t ToA, uint8_t fToA) : ToA(ToA), fToA(fToA), ToT(200), spidrTime(41503), tdcClockInPixelTime(16999999997), pixelClockTime(calculatePixelClockTime(spidrTime, ToA, fToA)) {} - PixelTimeTestHelper(int16_t ToA, uint8_t fToA, uint32_t spidrTime, + PixelTimeTestHelper(uint16_t ToA, uint8_t fToA, uint32_t spidrTime) + : ToA(ToA), fToA(fToA), ToT(200), spidrTime(spidrTime), + tdcClockInPixelTime(16999999997), + pixelClockTime(calculatePixelClockTime(spidrTime, ToA, fToA)) {} + + PixelTimeTestHelper(uint16_t ToA, uint8_t fToA, uint32_t spidrTime, uint64_t tdcClockInPixelTime) : ToA(ToA), fToA(fToA), ToT(200), spidrTime(spidrTime), tdcClockInPixelTime(tdcClockInPixelTime), @@ -145,8 +152,23 @@ TEST_F(Timepix3PixelEventHandlerTest, TestInvalidPixelReadout) { } TEST_F(Timepix3PixelEventHandlerTest, TestIfEventIsLaterThenNextTdc) { - // This value ensures that the pixel time is later then the tdc clock - uint32_t spidrLateArrival = 55000; + nanoseconds FrequencyPeriodNs = hzToNanoseconds(Timepix3Config.FrequencyHz); + + // This value ensures that the pixel time is later then the next tdc clock + uint32_t spidrDelayToPulse = 176; + + PixelTimeTestHelper PixelTimeInNextPulse{ + TEST_DEFAULT_PIXEL_TIME.ToA, TEST_DEFAULT_PIXEL_TIME.fToA, + TEST_DEFAULT_PIXEL_TIME.spidrTime + spidrDelayToPulse, + TEST_DEFAULT_PIXEL_TIME.tdcClockInPixelTime}; + + serializer.pulseTimeToCompare = TEST_PULSE_TIME_NS; + serializer.pixelIdToCompare = TEST_PIXEL_ID; + + // Pixel tof should be normalized with the frequency period to fir to the + // current pulse + serializer.eventTimeToCompare = + PixelTimeInNextPulse.getEventTof() % FrequencyPeriodNs.count(); serializer.pulseTimeToCompare = TEST_PULSE_TIME_NS; @@ -154,13 +176,15 @@ TEST_F(Timepix3PixelEventHandlerTest, TestIfEventIsLaterThenNextTdc) { {TEST_PULSE_TIME_NS, TEST_DEFAULT_PIXEL_TIME.tdcClockInPixelTime}); testEventHandler.applyData( - PixelReadout{TEST_DCOL, TEST_SPIX, TEST_PIX, TEST_DEFAULT_PIXEL_TIME.ToA, - TEST_DEFAULT_PIXEL_TIME.ToT, TEST_DEFAULT_PIXEL_TIME.fToA, - spidrLateArrival}); + PixelReadout{TEST_DCOL, TEST_SPIX, TEST_PIX, PixelTimeInNextPulse.ToA, + PixelTimeInNextPulse.ToT, PixelTimeInNextPulse.fToA, + PixelTimeInNextPulse.spidrTime}); testEventHandler.pushDataToKafka(); EXPECT_EQ(counters.EventTimeForNextPulse, 1); - EXPECT_EQ(serializer.addEventCallCounter, 0); + + // We always add event since we normalize it to current pulse. + EXPECT_EQ(serializer.addEventCallCounter, 1); } TEST_F(Timepix3PixelEventHandlerTest, TestEventTimeShortlyAfterTdcPublished) {