DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TPWindow.cpp
Go to the documentation of this file.
1
3
4#include <chrono>
5#include <map>
6#include <memory>
7#include <string>
8#include <unordered_set>
9#include <utility>
10
11namespace triggeralgs {
12
13bool
15{
16 return inputs.empty();
17}
18
19void
21{
22 // Add the input TP's contribution to the total ADC, increase hit
23 // channel's hit count and add it to the TP list.
24 adc_integral += input_tp.adc_integral;
25 channel_states[input_tp.channel]++;
26 inputs.push_back(input_tp);
27}
28
29void
31{
32 inputs.clear();
33 channel_states.clear();
34 time_start = 0;
35 adc_integral = 0;
36}
37
38uint16_t
40{
41 return channel_states.size();
42}
43
44void
45TPWindow::move(TriggerPrimitive const& input_tp, timestamp_t const& window_length)
46{
47 // Find all of the TPs in the window that need to be removed
48 // if the input_tp is to be added and the size of the window
49 // is to be conserved.
50 // Substract those TPs' contribution from the total window ADC and remove their
51 // contributions to the hit counts.
52 uint32_t n_tps_to_erase = 0;
53 for (auto tp : inputs) {
54 if (!(input_tp.time_start - tp.time_start < window_length)) {
55 n_tps_to_erase++;
56 adc_integral -= tp.adc_integral;
57 channel_states[tp.channel]--;
58 // If a TP being removed from the window results in a channel no longer having
59 // any hits, remove from the states map so map.size() can be used for number
60 // channels hit.
61 if (channel_states[tp.channel] == 0)
62 channel_states.erase(tp.channel);
63 } else
64 break;
65 }
66 // Erase the TPs from the window.
67 inputs.erase(inputs.begin(), inputs.begin() + n_tps_to_erase);
68 // Make the window start time the start time of what is now the first TP.
69
70 if (inputs.size() != 0) {
71 time_start = inputs.front().time_start;
72 add(input_tp);
73 } else {
74 reset(input_tp);
75 }
76}
77
78void
80{
81
82 // Empty the channel and TP lists.
83 channel_states.clear();
84 inputs.clear();
85 // Set the start time of the window to be the start time of theinput_tp.
86 time_start = input_tp.time_start;
87 // Start the total ADC integral.
88 adc_integral = input_tp.adc_integral;
89 // Start hit count for the hit channel.
90 channel_states[input_tp.channel]++;
91 // Add the input TP to the TP list.
92 inputs.push_back(input_tp);
93 // std::cout << "Number of channels hit: " << n_channels_hit() << std::endl;
94}
95
96std::ostream&
97operator<<(std::ostream& os, const TPWindow& window)
98{
99 if (window.is_empty()) {
100 os << "Window is empty!\n";
101 } else {
102 os << "Window start: " << window.time_start << ", end: " << window.inputs.back().time_start;
103 os << ". Total of: " << window.adc_integral << " ADC counts with " << window.inputs.size() << " TPs.\n";
104 os << window.channel_states.size() << " independent channels have hits.\n";
105 }
106 return os;
107}
108
109} // namespace triggeralgs
void reset(TriggerPrimitive const &input_tp)
Definition TPWindow.cpp:79
std::unordered_map< channel_t, uint16_t > channel_states
Definition TPWindow.hpp:39
void add(TriggerPrimitive const &input_tp)
Definition TPWindow.cpp:20
bool is_empty() const
Definition TPWindow.cpp:14
std::vector< TriggerPrimitive > inputs
Definition TPWindow.hpp:40
void move(TriggerPrimitive const &input_tp, timestamp_t const &window_length)
Definition TPWindow.cpp:45
timestamp_t time_start
Definition TPWindow.hpp:37
uint16_t n_channels_hit()
Definition TPWindow.cpp:39
dunedaq::trgdataformats::timestamp_t timestamp_t
Definition Types.hpp:16
std::ostream & operator<<(std::ostream &os, const TAWindow &window)
Definition TAWindow.cpp:98
A single energy deposition on a TPC or PDS channel.