DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TAMakerMichelElectronAlgorithm.hpp
Go to the documentation of this file.
1
9#ifndef TRIGGERALGS_MICHELELECTRON_TRIGGERACTIVITYMAKERMICHELELECTRON_HPP_
10#define TRIGGERALGS_MICHELELECTRON_TRIGGERACTIVITYMAKERMICHELELECTRON_HPP_
11
13#include <fstream>
14#include <vector>
15
16namespace triggeralgs {
18{
19
20public:
21 void process(const TriggerPrimitive& input_tp, std::vector<TriggerActivity>& output_ta);
22
23 void configure(const nlohmann::json& config);
24
25private:
26 class Window
27 {
28 public:
29 bool is_empty() const { return inputs.empty(); };
30 void add(TriggerPrimitive const& input_tp)
31 {
32 // Add the input TP's contribution to the total ADC, increase hit channel's hit count and add it to the TP list.
33 adc_integral += input_tp.adc_integral;
34 channel_states[input_tp.channel]++;
35 inputs.push_back(input_tp);
36 };
37 void clear() { inputs.clear(); };
38 uint16_t n_channels_hit() { return channel_states.size(); };
39 void move(TriggerPrimitive const& input_tp, timestamp_t const& window_length)
40 {
41 // Find all of the TPs in the window that need to be removed
42 // if the input_tp is to be added and the size of the window
43 // is to be conserved.
44 // Substract those TPs' contribution from the total window ADC and remove their
45 // contributions to the hit counts.
46 uint32_t n_tps_to_erase = 0;
47 for (auto tp : inputs) {
48 if (!(input_tp.time_start - tp.time_start < window_length)) {
49 n_tps_to_erase++;
50 adc_integral -= tp.adc_integral;
51 channel_states[tp.channel]--;
52 // If a TP being removed from the window results in a channel no longer having
53 // any hits, remove from the states map so map.size() can be used for number
54 // channels hit.
55 if (channel_states[tp.channel] == 0)
56 channel_states.erase(tp.channel);
57 } else
58 break;
59 }
60 // Erase the TPs from the window.
61 inputs.erase(inputs.begin(), inputs.begin() + n_tps_to_erase);
62 // Make the window start time the start time of what is now the first TP.
63
64 if (!(inputs.size() == 0)) {
65 time_start = inputs.front().time_start;
66 add(input_tp);
67 } else {
68 // std::cout << "Resetting window." << std::endl;
69 reset(input_tp);
70 }
71 };
72 void reset(TriggerPrimitive const& input_tp)
73 {
74
75 // Empty the channel and TP lists.
76 channel_states.clear();
77 inputs.clear();
78 // Set the start time of the window to be the start time of theinput_tp.
79 time_start = input_tp.time_start;
80 // Start the total ADC integral.
81 adc_integral = input_tp.adc_integral;
82 // Start hit count for the hit channel.
83 channel_states[input_tp.channel]++;
84 // Add the input TP to the TP list.
85 inputs.push_back(input_tp);
86 // std::cout << "Number of channels hit: " << n_channels_hit() << std::endl;
87 };
88 friend std::ostream& operator<<(std::ostream& os, const Window& window)
89 {
90 if (window.is_empty())
91 os << "Window is empty!\n";
92 else {
93 os << "Window start: " << window.time_start << ", end: " << window.inputs.back().time_start;
94 os << ". Total of: " << window.adc_integral << " ADC counts with " << window.inputs.size() << " TPs.\n";
95 os << window.channel_states.size() << " independent channels have hits.\n";
96 }
97 return os;
98 };
99
101 uint32_t adc_integral;
102 std::unordered_map<channel_t, uint16_t> channel_states;
103 std::vector<TriggerPrimitive> inputs;
104 };
105
107 std::vector<TriggerPrimitive> longest_activity() const;
108 bool check_bragg_peak(std::vector<TriggerPrimitive> trackHits);
109 bool check_kinks(std::vector<TriggerPrimitive> trackHits);
110
112 uint64_t m_primitive_count = 0;
113
114 // Configurable parameters.
115 // triggeractivitymakerhorizontalmuon::ConfParams m_conf;
116 bool debug = false; // Use to control whether functions write out useful info
117 uint16_t m_adjacency_threshold = 15; // Default is 15 for trigger
118 int m_max_adjacency = 0; // The maximum adjacency seen so far in any window
119 uint16_t m_adj_tolerance = 3; // Adjacency tolerance - default is 3 from coldbox testing.
120 int index = 0;
121 uint16_t ta_adc = 0;
122 uint16_t ta_channels = 0;
124
125 // For debugging purposes.
126 void add_window_to_record(Window window);
127 void dump_window_record();
128 void dump_tp(TriggerPrimitive const& input_tp);
129 std::vector<Window> m_window_record;
130};
131} // namespace triggeralgs
132
133#endif // TRIGGERALGS_MICHELELECTRON_TRIGGERACTIVITYMAKERMICHELELECTRON_HPP_
friend std::ostream & operator<<(std::ostream &os, const Window &window)
void move(TriggerPrimitive const &input_tp, timestamp_t const &window_length)
std::vector< TriggerPrimitive > longest_activity() const
bool check_kinks(std::vector< TriggerPrimitive > trackHits)
bool check_bragg_peak(std::vector< TriggerPrimitive > trackHits)
void process(const TriggerPrimitive &input_tp, std::vector< TriggerActivity > &output_ta)
TP processing function that creates & fills TAs.
dunedaq::trgdataformats::timestamp_t timestamp_t
Definition Types.hpp:16
A single energy deposition on a TPC or PDS channel.