Skip to content

Commit 38b4271

Browse files
committed
Add more details in log messages about dropped digis and the sorting window
1 parent e107a43 commit 38b4271

4 files changed

Lines changed: 23 additions & 14 deletions

File tree

core/opengate_core/opengate_lib/digitizer/GateCoincidenceSorterActor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void GateCoincidenceSorterActor::BeginOfRunActionMasterThread(int run_id) {
176176
// digis from all threads, so that the coincidence actor can identify
177177
// coincidences between singles, irrespective of the thread in which they were
178178
// simulated (prompt as well as random coincidences).
179-
fTimeSorter = std::make_unique<GateTimeSorter>();
179+
fTimeSorter = std::make_unique<GateTimeSorter>(fOutputDigiCollectionName);
180180
fTimeSorter->Init(fInputDigiCollection);
181181
fTimeSorter->SetSortingWindow(fSortingTime);
182182
fTimeSorter->SetMaxSize(fClearEveryNEvents);

core/opengate_core/opengate_lib/digitizer/GateDigitizerPileupActor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void GateDigitizerPileupActor::InitializeUserInfo(py::dict &user_info) {
7171

7272
void GateDigitizerPileupActor::BeginOfRunActionMasterThread(int run_id) {
7373

74-
fTimeSorter = std::make_unique<GateTimeSorter>();
74+
fTimeSorter = std::make_unique<GateTimeSorter>(fOutputDigiCollectionName);
7575
fTimeSorter->Init(fInputDigiCollection);
7676
fTimeSorter->SetSortingWindow(fSortingTime);
7777
fTimeSorter->SetMaxSize(fClearEveryNEvents);

core/opengate_core/opengate_lib/digitizer/GateTimeSorter.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <memory>
77
#include <utility>
88

9-
GateTimeSorter::GateTimeSorter() {
9+
GateTimeSorter::GateTimeSorter(const std::string &name) : fName(name) {
1010
fNumWorkingThreads =
1111
std::max(1, G4Threading::GetNumberOfRunningWorkerThreads());
1212
fNumActiveWorkingThreads.store(fNumWorkingThreads);
@@ -326,6 +326,7 @@ void GateTimeSorter::Process() {
326326
while (!iter.IsAtEnd()) {
327327
const size_t digiIndex = fSortedCollectionA->GetSize();
328328
const double digiTime = *t;
329+
fNumDigi++;
329330
// If a digi is older (lower GlobalTime value) than the newest digi that has
330331
// already been transferred to the output collection, then this digi must be
331332
// dropped to be able to guarantee time-monotonicity in the output
@@ -337,13 +338,14 @@ void GateTimeSorter::Process() {
337338
if (fMostRecentTimeDeparted.has_value() &&
338339
(digiTime < *fMostRecentTimeDeparted)) {
339340
++fNumDroppedDigi;
341+
fMaxDropDelta =
342+
std::max(fMaxDropDelta, *fMostRecentTimeDeparted - digiTime);
340343
if (!fSortingWindowWarningIssued) {
341-
std::cout << "The digis in " << fInputCollection->GetName()
342-
<< " have non-monotonicities in the GlobalTime attribute "
343-
"that exceed the sorting time ("
344-
<< fMinimumSortingWindow
345-
<< " ns). Please increase the sorting window to avoid "
346-
"dropped digis\n";
344+
std::cout << "The digis output by actor '"
345+
<< fInputCollection->GetName()
346+
<< "' have non-monotonicities in the GlobalTime attribute "
347+
"that exceed the sorting time in actor '"
348+
<< fName << "' (" << fMinimumSortingWindow << " ns).\n";
347349
fSortingWindowWarningIssued = true;
348350
}
349351
} else {
@@ -414,10 +416,14 @@ void GateTimeSorter::Flush() {
414416
Prune();
415417
fFlushed = true;
416418
if (fNumDroppedDigi > 0) {
417-
std::cout << fNumDroppedDigi
418-
<< " digis have been dropped while time-sorting. Please increase "
419-
"the sorting time to a value higher than "
420-
<< fMinimumSortingWindow << " ns\n";
419+
const auto percentage =
420+
static_cast<double>(fNumDroppedDigi) / fNumDigi * 100;
421+
std::cout << fNumDroppedDigi << " digis (" << percentage
422+
<< " %) have been dropped while time-sorting in actor '" << fName
423+
<< "'. Please increase the sorting time to a value higher than "
424+
"the current "
425+
<< fMinimumSortingWindow << " ns (suggestion: > " << fMaxDropDelta
426+
<< "ns)\n";
421427
}
422428
}
423429

core/opengate_core/opengate_lib/digitizer/GateTimeSorter.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class GateDigiAttributesFiller;
1515

1616
class GateTimeSorter {
1717
public:
18-
GateTimeSorter();
18+
GateTimeSorter(const std::string &name);
1919

2020
void Init(GateDigiCollection *input);
2121

@@ -93,11 +93,14 @@ class GateTimeSorter {
9393

9494
// GateTimeSorter internal state
9595

96+
std::string fName{};
9697
bool fInitialized{false};
9798
bool fProcessingStarted{false};
9899
bool fFlushed{false};
99100
bool fSortingWindowWarningIssued{false};
100101
size_t fNumDroppedDigi{};
102+
size_t fNumDigi{};
103+
double fMaxDropDelta{};
101104
std::optional<double> fMostRecentTimeArrived;
102105
std::optional<double> fMostRecentTimeDeparted;
103106
};

0 commit comments

Comments
 (0)