CbmRoot
Loading...
Searching...
No Matches
TimeClusterTrigger.cxx
Go to the documentation of this file.
1/* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer], Dominik Smith */
4
6
7#include <algorithm>
8#include <cassert>
9#include <iterator>
10#include <sstream>
11#include <vector>
12
13#include <xpu/host.h>
14
15using std::string;
16using std::stringstream;
17using std::vector;
18
19namespace cbm::algo::evbuild
20{
21
23 {
24
25 if (!std::is_sorted(dataVec.begin(), dataVec.end())) throw std::runtime_error("TimeClusterTrigger: unsorted input");
26
27 xpu::push_timer("TimeClusterTrigger");
28 xpu::t_add_bytes(dataVec.size() * sizeof(double));
29
30 // --- Output data
31 resultType result = {};
32 vector<double>& triggerVec = result.first;
33 TimeClusterTriggerMonitorData& monitor = result.second;
34
35 auto winStart = dataVec.begin();
36 auto current = dataVec.begin();
37
38 while (current != dataVec.end()) {
39
40 // If window size is exceeded, adjust window start
41 while (*current - *winStart > fWinSize)
42 winStart++;
43
44 // Create trigger if threshold is reached
45 if (std::distance(winStart, current) >= fMinNumData - 1) {
46 triggerVec.push_back(0.5 * (*current + *winStart));
47
48 // Increment monitoring counter with number of digis used
49 monitor.numInTrigger += std::distance(winStart, current) + 1;
50
51 // Start new window after dead time
52 winStart = current + 1;
53 while (winStart != dataVec.end() && *winStart - *current <= fDeadTime)
54 winStart++;
55 current = winStart;
56 }
57
58 // If threshold is not reached, check with next element
59 else
60 current++;
61 }
62 // Store number of input data for monitoring
63 monitor.num += dataVec.size();
64 monitor.nTriggers = triggerVec.size();
65
66 monitor.time = xpu::pop_timer();
67
68 return result;
69 }
70
71
73 {
74 stringstream out;
75 out << "--- Using TimeClusterTrigger with trigger window " << fWinSize << " ns";
76 out << ", threshold " << fMinNumData;
77 out << ", dead time " << fDeadTime << " ns";
78 return out.str();
79 }
80
81} // namespace cbm::algo::evbuild
resultType operator()(const std::vector< double > &dataVec) const
Execution.
std::string ToString() const
Info to string.
std::pair< std::vector< double >, TimeClusterTriggerMonitorData > resultType
Monitoring data for time cluster trigger algorithm.
size_t numInTrigger
Time stamps used for trigger building.
xpu::timings time
Time for trigger building.