All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PMTTrigger.cc
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include "PMTTrigger.h"
4 
5 #include "sbndcode/OpDetSim/sbndPDMapAlg.h"
6 
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;
9 
10  opdet::sbndPDMapAlg mapalg;
11  for (const raw::OpDetWaveform &wvf: waveforms) {
12  // check if this is a PMT
13  bool is_pmt = (!is_sbnd) || mapalg.isPDType(wvf.ChannelNumber(), "pmt");
14 
15  if (!is_pmt) continue;
16 
17  // look for any overlap with the enable window
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());
21 
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) { // PMT waveforms go down
27  FlashTriggerPrimitive::Trig this_trig {wvf[i], i + (int)((waveform_start - window.first) / tick_period)};
28  prim.triggers.push_back(this_trig);
29  }
30  }
31  ret.push_back(prim);
32  }
33  }
34  return ret;
35 }
36 
37 std::vector<int> numu::TriggerThresholds(const std::vector<numu::FlashTriggerPrimitive> &primitives, unsigned size) {
38  std::map<int, std::vector<int>> trigs;
39  for (const numu::FlashTriggerPrimitive &primitive: primitives) {
40  for (const numu::FlashTriggerPrimitive::Trig &trig: primitive.triggers) {
41  trigs[trig.tdc].push_back(trig.adc);
42  }
43  }
44 
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());
49  }
50 
51  std::vector<int> ret;
52  for (unsigned i = 1; i <= size; i++) {
53  int min = 8000;
54  for (const auto &pair: time_sorted) {
55  if (pair.second.first >= i) {
56  if (pair.second.second < min) min = pair.second.second;
57  }
58  }
59  ret.push_back(min);
60  }
61 
62  return ret;
63 }
64 
65 bool numu::HasTrigger(const std::vector<numu::FlashTriggerPrimitive> &primitives, int threshold, unsigned n_above_threshold) {
66  if (n_above_threshold == 0) return true;
67 
68  std::map<int, std::vector<unsigned>> above_threshold;
69 
70  for (const numu::FlashTriggerPrimitive &primitive: primitives) {
71  for (const numu::FlashTriggerPrimitive::Trig &trig: primitive.triggers) {
72  if (trig.adc <= threshold) {
73  above_threshold[trig.tdc].push_back(primitive.channel);
74  }
75  }
76  }
77 
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 << " ";
81  std::cout << std::endl;
82  if (pair.second.size() >= n_above_threshold) {
83  return true;
84  }
85  }
86 
87  return false;
88 }
89 
90 
std::vector< FlashTriggerPrimitive > TriggerPrimitives(const std::vector< raw::OpDetWaveform > &waveforms, double tick_period, std::pair< double, double > &window, int thresh, bool is_sbnd)
Definition: PMTTrigger.cc:7
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
bool isPDType(size_t ch, std::string pdname) const override
std::vector< int > TriggerThresholds(const std::vector< numu::FlashTriggerPrimitive > &primitives, unsigned size)
Definition: PMTTrigger.cc:37
std::vector< Trig > triggers
Definition: DetInfo.h:26
int tick_period
Definition: constants.py:3
bool HasTrigger(const std::vector< FlashTriggerPrimitive > &primitives, int threshold, unsigned n_above_threshold)
Definition: PMTTrigger.cc:65
BEGIN_PROLOG could also be cout