SignalROI.cxx
Go to the documentation of this file.
1 #include "SignalROI.h"
2 
3 #include <algorithm>
4 
5 using namespace WireCell;
6 using namespace WireCell::SigProc;
7 
8 SignalROI::SignalROI(int plane, int chid, int start_bin, int end_bin, const Waveform::realseq_t& signal)
9  : plane(plane)
10  , chid(chid)
11  , start_bin(start_bin)
12  , end_bin(end_bin)
13 {
14  float start_content = signal.at(start_bin);
15  float end_content = signal.at(end_bin);
16  contents.resize(end_bin-start_bin+1);
17 
18  for (int i=start_bin; i<= end_bin; i++){
19  float content = signal.at(i) - ((end_content - start_content)*(i-start_bin)/(end_bin-start_bin) + start_content);
20  contents.at(i-start_bin) = content;
21  }
22 }
23 
25  plane = roi->get_plane();
26  chid = roi->get_chid();
27  start_bin = roi->get_start_bin();
28  end_bin = roi->get_end_bin();
29  for (int i=start_bin; i<=end_bin;i++){
30  contents.push_back(roi->get_contents().at(i-start_bin));
31  }
32 }
33 
35  double max = -1e9;
36  for (size_t i=0;i!=contents.size();i++){
37  if (max < contents.at(i))
38  max = contents.at(i);
39  }
40  return max;
41 }
42 
44  double sum1 = 0;
45  double sum2 = 0;
46  for (size_t i=0;i!=contents.size();i++){
47  sum1 += contents.at(i);
48  sum2 ++;
49  }
50  if (sum2!=0){
51  return sum1/sum2;
52  }else{
53  return 0;
54  }
55 }
56 
57 bool SignalROI::overlap(SignalROI* roi1, float th, float th1){
58  int min_start_bin = start_bin;
59  if (start_bin < roi1->get_start_bin())
60  min_start_bin = roi1->get_start_bin();
61  int min_end_bin = end_bin;
62  if (end_bin > roi1->get_end_bin())
63  min_end_bin = roi1->get_end_bin();
64  if (min_end_bin > min_start_bin){
65  std::vector<float>& contents1 = roi1->get_contents();
66 
67  for (int i=min_start_bin; i<= min_end_bin; i++){
68  if (contents.at(i-start_bin) > th &&
69  contents1.at(i-roi1->get_start_bin())>th1){
70  return true;
71  }
72  }
73 
74  return false;
75  }else{
76  return false;
77  }
78 }
79 
81 
82  int min_start_bin = start_bin;
83  if (start_bin < roi->get_start_bin())
84  min_start_bin = roi->get_start_bin();
85  int min_end_bin = end_bin;
86  if (end_bin > roi->get_end_bin())
87  min_end_bin = roi->get_end_bin();
88  if (min_end_bin > min_start_bin){
89  return true;
90  }else{
91  return false;
92  }
93  // if (start_bin < roi->get_end_bin() && end_bin >= roi->get_end_bin())
94  // return true;
95  // if (start_bin <= roi->get_start_bin() && end_bin > roi->get_start_bin())
96  // return true;
97  // if (start_bin >= roi->get_start_bin() && end_bin <= roi->get_end_bin())
98  // return true;
99  //return false;
100 }
101 
102 
103 
105 }
106 
107 
108 
109 std::vector<std::pair<int,int>> SignalROI::get_above_threshold(float th){
110  std::vector<std::pair<int,int>> bins;
111  for (int i=0;i<int(contents.size());i++){
112  if (contents.at(i) > th){
113  int start = i;
114  int end = i;
115  for (int j=i+1;j<int(contents.size());j++){
116  if (contents.at(j) > th){
117  end = j;
118  }else{
119  break;
120  }
121  }
122  bins.push_back(std::make_pair(start,end));
123  i = end;
124  }
125  }
126 
127  return bins;
128 }
Sequence< real_t > realseq_t
Definition: Waveform.h:31
Val sum2(const Sequence< Val > &seq)
Return sum of square of all entries in sequence.
Definition: Waveform.h:184
std::vector< std::pair< int, int > > get_above_threshold(float th)
Definition: SignalROI.cxx:109
std::vector< float > contents
Definition: SignalROI.h:48
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:72
std::vector< float > & get_contents()
Definition: SignalROI.h:30
SignalROI(int plane, int chid, int start_bin, int end_bin, const Waveform::realseq_t &signal)
Definition: SignalROI.cxx:8
static int max(int a, int b)
bool overlap(SignalROI *roi)
Definition: SignalROI.cxx:80
Definition: Main.h:22