DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
triggeralgs
src
TPWindow.cpp
Go to the documentation of this file.
1
2
#include "
triggeralgs/TPWindow.hpp
"
3
4
#include <chrono>
5
#include <map>
6
#include <memory>
7
#include <string>
8
#include <unordered_set>
9
#include <utility>
10
11
namespace
triggeralgs
{
12
13
bool
14
TPWindow::is_empty
()
const
15
{
16
return
inputs
.empty();
17
}
18
19
void
20
TPWindow::add
(
TriggerPrimitive
const
& input_tp)
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
29
void
30
TPWindow::clear
()
31
{
32
inputs
.clear();
33
channel_states
.clear();
34
time_start
= 0;
35
adc_integral
= 0;
36
}
37
38
uint16_t
39
TPWindow::n_channels_hit
()
40
{
41
return
channel_states
.size();
42
}
43
44
void
45
TPWindow::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
78
void
79
TPWindow::reset
(
TriggerPrimitive
const
& input_tp)
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
96
std::ostream&
97
operator<<
(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
TPWindow.hpp
triggeralgs::TPWindow
Definition
TPWindow.hpp:21
triggeralgs::TPWindow::reset
void reset(TriggerPrimitive const &input_tp)
Definition
TPWindow.cpp:79
triggeralgs::TPWindow::channel_states
std::unordered_map< channel_t, uint16_t > channel_states
Definition
TPWindow.hpp:39
triggeralgs::TPWindow::add
void add(TriggerPrimitive const &input_tp)
Definition
TPWindow.cpp:20
triggeralgs::TPWindow::is_empty
bool is_empty() const
Definition
TPWindow.cpp:14
triggeralgs::TPWindow::inputs
std::vector< TriggerPrimitive > inputs
Definition
TPWindow.hpp:40
triggeralgs::TPWindow::move
void move(TriggerPrimitive const &input_tp, timestamp_t const &window_length)
Definition
TPWindow.cpp:45
triggeralgs::TPWindow::adc_integral
uint32_t adc_integral
Definition
TPWindow.hpp:38
triggeralgs::TPWindow::clear
void clear()
Definition
TPWindow.cpp:30
triggeralgs::TPWindow::time_start
timestamp_t time_start
Definition
TPWindow.hpp:37
triggeralgs::TPWindow::n_channels_hit
uint16_t n_channels_hit()
Definition
TPWindow.cpp:39
triggeralgs
Definition
AbstractFactory.hpp:18
triggeralgs::timestamp_t
dunedaq::trgdataformats::timestamp_t timestamp_t
Definition
Types.hpp:16
triggeralgs::TriggerPrimitive
dunedaq::trgdataformats::TriggerPrimitive TriggerPrimitive
Definition
TriggerPrimitive.hpp:22
triggeralgs::operator<<
std::ostream & operator<<(std::ostream &os, const ProtoDUNEBSMWindow &window)
Definition
ProtoDUNEBSMWindow.cpp:108
dunedaq::trgdataformats::TriggerPrimitive::channel
uint64_t channel
Definition
TriggerPrimitive.hpp:36
dunedaq::trgdataformats::TriggerPrimitive::time_start
uint64_t time_start
Definition
TriggerPrimitive.hpp:39
dunedaq::trgdataformats::TriggerPrimitive::adc_integral
uint64_t adc_integral
Definition
TriggerPrimitive.hpp:42
Generated on
for DUNE-DAQ by
1.17.0