5 #include "sbndcode/OpDetSim/sbndPDMapAlg.h"
7 std::vector<numu::FlashTriggerPrimitive>
numu::TriggerPrimitives(
const std::vector<raw::OpDetWaveform> &waveforms,
double tick_period, std::pair<double, double> &window,
int thresh,
bool is_sbnd) {
8 std::vector<numu::FlashTriggerPrimitive> ret;
13 bool is_pmt = (!is_sbnd) || mapalg.
isPDType(wvf.ChannelNumber(),
"pmt");
15 if (!is_pmt)
continue;
18 double waveform_start = wvf.TimeStamp();
19 int waveform_index_start = std::max((
int)((window.first - waveform_start) / tick_period), 0);
20 int waveform_index_end = std::min((
int)((window.second - waveform_start) / tick_period), (
int) wvf.size());
22 if (waveform_index_start < waveform_index_end) {
24 prim.
channel = wvf.ChannelNumber();
25 for (
int i = waveform_index_start; i < waveform_index_end; i++) {
26 if (wvf[i] <= thresh) {
38 std::map<int, std::vector<int>> trigs;
41 trigs[trig.
tdc].push_back(trig.
adc);
45 std::map<int, std::pair<unsigned, int>> time_sorted;
46 for (
const auto &pair: trigs) {
47 time_sorted[pair.first].first = pair.second.size();
48 time_sorted[pair.first].second = *std::max_element(pair.second.begin(), pair.second.end());
52 for (
unsigned i = 1; i <=
size; i++) {
54 for (
const auto &pair: time_sorted) {
55 if (pair.second.first >= i) {
56 if (pair.second.second < min) min = pair.second.second;
65 bool numu::HasTrigger(
const std::vector<numu::FlashTriggerPrimitive> &primitives,
int threshold,
unsigned n_above_threshold) {
66 if (n_above_threshold == 0)
return true;
68 std::map<int, std::vector<unsigned>> above_threshold;
72 if (trig.
adc <= threshold) {
73 above_threshold[trig.
tdc].push_back(primitive.channel);
78 for (
auto const &pair: above_threshold) {
79 std::cout <<
"At time: " << pair.first <<
" above thresh: ";
80 for (
unsigned ch: pair.second)
std::cout << ch <<
" ";
82 if (pair.second.size() >= n_above_threshold) {
std::vector< FlashTriggerPrimitive > TriggerPrimitives(const std::vector< raw::OpDetWaveform > &waveforms, double tick_period, std::pair< double, double > &window, int thresh, bool is_sbnd)
std::size_t size(FixedBins< T, C > const &) noexcept
bool isPDType(size_t ch, std::string pdname) const override
std::vector< int > TriggerThresholds(const std::vector< numu::FlashTriggerPrimitive > &primitives, unsigned size)
std::vector< Trig > triggers
bool HasTrigger(const std::vector< FlashTriggerPrimitive > &primitives, int threshold, unsigned n_above_threshold)
BEGIN_PROLOG could also be cout