PMTNoiseROI.cxx
Go to the documentation of this file.
1 #include "PMTNoiseROI.h"
2 
3 #include <algorithm>
4 #include <cmath>
5 
6 using namespace WireCell;
7 
8 using namespace WireCell::SigProc;
9 
10 PMTNoiseROI::PMTNoiseROI(int start_bin, int end_bin, int peak, int channel, float peak_height)
11  : start_bin(start_bin)
12  , end_bin(end_bin)
13 {
14  peaks.push_back(peak);
15  collection_wwires.push_back(channel);
16  wwires_peak_heights[channel] = fabs(peak_height);
17 }
18 
19 
21 
22 }
23 
24 void PMTNoiseROI::insert_peak(int peak){
25  if (find(peaks.begin(),peaks.end(),peak)==peaks.end())
26  peaks.push_back(peak);
27 }
28 
29 
30 void PMTNoiseROI::insert_uwires(int wire_no, float peak_height){
31  if (find(induction_uwires.begin(),induction_uwires.end(),wire_no)==induction_uwires.end()){
32  induction_uwires.push_back(wire_no);
33  uwires_peak_heights[wire_no] = peak_height;
34  }
35 }
36 
37 void PMTNoiseROI::insert_vwires(int wire_no, float peak_height){
38  if (find(induction_vwires.begin(),induction_vwires.end(),wire_no)==induction_vwires.end()){
39  induction_vwires.push_back(wire_no);
40  vwires_peak_heights[wire_no] = peak_height;
41  }
42 }
43 
45  float max = 0;
46  for (int i=0;i!=int(sorted_col_wwires.size());i++){
49  }
50  return max;
51 }
52 
54  float ave = 0 ;
55  float ave1 = 0 ;
56  for (int i=0;i!=int(sorted_col_wwires.size());i++){
58  ave1 ++;
59  }
60  if (ave1 >0){
61  return ave/ave1;
62  }else{
63  return 0;
64  }
65 }
66 
67 
69  float max = 0;
70  if (group < int(sorted_ind_uwires.size())){
71  for (int i=0;i!=int(sorted_ind_uwires.at(group).size());i++){
72  if (uwires_peak_heights[sorted_ind_uwires.at(group).at(i)] > max)
73  max= uwires_peak_heights[sorted_ind_uwires.at(group).at(i)];
74  }
75  }
76  return max;
77 }
78 
80  float max = 0;
81  if (group < int(sorted_ind_vwires.size())){
82  for (int i=0;i!=int(sorted_ind_vwires.at(group).size());i++){
83  if (vwires_peak_heights[sorted_ind_vwires.at(group).at(i)] > max)
84  max= vwires_peak_heights[sorted_ind_vwires.at(group).at(i)];
85  }
86  }
87  return max;
88 }
89 
91  float ave = 0 ;
92  float ave1 = 0 ;
93  if (group < int(sorted_ind_uwires.size())){
94  for (int i=0;i!=int(sorted_ind_uwires.at(group).size());i++){
95  ave += uwires_peak_heights[sorted_ind_uwires.at(group).at(i)];
96  ave1 ++;
97  }
98  }
99 
100  if (ave1 >0){
101  return ave/ave1;
102  }else{
103  return 0;
104  }
105 }
106 
108  float ave = 0 ;
109  float ave1 = 0 ;
110  if (group < int(sorted_ind_vwires.size())){
111  for (int i=0;i!=int(sorted_ind_vwires.at(group).size());i++){
112  ave += vwires_peak_heights[sorted_ind_vwires.at(group).at(i)];
113  ave1 ++;
114  }
115  }
116  if (ave1 >0){
117  return ave/ave1;
118  }else{
119  return 0;
120  }
121 }
122 
123 
125  // decide how to merge two ROIs? ...
126 
127  // one peak is contained in the other's range then merge
128  if ( (peaks.at(0)>=ROI.get_start_bin() && peaks.at(0)<=ROI.get_end_bin())
129  || (start_bin <= ROI.get_peaks().at(0) && end_bin >= ROI.get_peaks().at(0))){
130  if (ROI.get_start_bin() < start_bin)
131  start_bin = ROI.get_start_bin();
132  if (ROI.get_end_bin() > end_bin)
133  end_bin = ROI.get_end_bin();
134 
135  for (int i=0;i!=int(ROI.get_peaks().size());i++){
136  if (find(peaks.begin(),peaks.end(),ROI.get_peaks().at(i)) == peaks.end())
137  peaks.push_back(ROI.get_peaks().at(i));
138  }
139 
140  for (int i=0;i!=int(ROI.get_wwires().size());i++){
141  if (find(collection_wwires.begin(),collection_wwires.end(),ROI.get_wwires().at(i)) == collection_wwires.end()){
142  collection_wwires.push_back(ROI.get_wwires().at(i));
143  }
144 
145  // calculate wire height
146  if (wwires_peak_heights.find(ROI.get_wwires().at(i))==wwires_peak_heights.end()){
147  wwires_peak_heights[ROI.get_wwires().at(i)] = ROI.get_wwires_peak_heights()[ROI.get_wwires().at(i)];
148  }else{
149  if (ROI.get_wwires_peak_heights()[ROI.get_wwires().at(i)] > wwires_peak_heights[ROI.get_wwires().at(i)])
150  wwires_peak_heights[ROI.get_wwires().at(i)] = ROI.get_wwires_peak_heights()[ROI.get_wwires().at(i)];
151  }
152 
153  }
154 
155  // for (int i=0;i!=ROI.get_wwires_peak_heights().size();i++){
156  // wwires_peak_heights.push_back(ROI.get_wwires_peak_heights().at(i));
157  //}
158 
159 
160 
161  return true;
162  }
163 
164  return false;
165 }
166 
167 
168 void PMTNoiseROI::sort_wires(int nwire){
169 
170  std::vector<int> temp_wires;
171  if (int(induction_uwires.size()) >=nwire){
172  std::sort(induction_uwires.begin(),induction_uwires.end());
173  temp_wires.push_back(induction_uwires.at(0));
174  // do u wires;
175  for (int i=1;i<int(induction_uwires.size());i++){
176  if (induction_uwires.at(i) - temp_wires.back() == 1){
177  temp_wires.push_back(induction_uwires.at(i));
178  }else{
179  if (int(temp_wires.size()) >= nwire){
180  sorted_ind_uwires.push_back(temp_wires);
181  }
182  temp_wires.clear();
183  temp_wires.push_back(induction_uwires.at(i));
184  }
185  }
186  if (int(temp_wires.size()) >= nwire){
187  sorted_ind_uwires.push_back(temp_wires);
188  }
189  temp_wires.clear();
190  }
191 
192  if (int(induction_vwires.size()) >=nwire){
193  std::sort(induction_vwires.begin(),induction_vwires.end());
194  temp_wires.push_back(induction_vwires.at(0));
195  // do u wires;
196  for (int i=1;i<int(induction_vwires.size());i++){
197  if (induction_vwires.at(i) - temp_wires.back() == 1){
198  temp_wires.push_back(induction_vwires.at(i));
199  }else{
200  if (int(temp_wires.size()) >= nwire){
201  sorted_ind_vwires.push_back(temp_wires);
202  }
203  temp_wires.clear();
204  temp_wires.push_back(induction_vwires.at(i));
205  }
206  }
207  if (int(temp_wires.size()) >= nwire){
208  sorted_ind_vwires.push_back(temp_wires);
209  }
210  temp_wires.clear();
211  }
212 
213 
214  if (int(collection_wwires.size()) >=nwire){
215  std::sort(collection_wwires.begin(),collection_wwires.end());
216  temp_wires.push_back(collection_wwires.at(0));
217  // do u wires;
218  for (int i=1;i<int(collection_wwires.size());i++){
219  if (collection_wwires.at(i) - temp_wires.back() == 1){
220  temp_wires.push_back(collection_wwires.at(i));
221  }else{
222  if (int(temp_wires.size()) >= nwire){
223  for (int j=0;j!=int(temp_wires.size());j++){
224  sorted_col_wwires.push_back(temp_wires.at(j));
225  }
226  }
227  temp_wires.clear();
228  temp_wires.push_back(collection_wwires.at(i));
229  }
230  }
231  if (int(temp_wires.size()) >= nwire){
232  for (int j=0;j!=int(temp_wires.size());j++){
233  sorted_col_wwires.push_back(temp_wires.at(j));
234  }
235  }
236  temp_wires.clear();
237  }
238 
239 
240 }
std::map< int, float > uwires_peak_heights
Definition: PMTNoiseROI.h:56
float get_max_vwires_peak_height(int group)
Definition: PMTNoiseROI.cxx:79
void insert_uwires(int wire_no, float peak_height)
Definition: PMTNoiseROI.cxx:30
std::map< int, float > wwires_peak_heights
Definition: PMTNoiseROI.h:58
std::vector< int > induction_vwires
Definition: PMTNoiseROI.h:62
std::map< int, float > & get_wwires_peak_heights()
Definition: PMTNoiseROI.h:31
std::vector< std::vector< int > > sorted_ind_vwires
Definition: PMTNoiseROI.h:66
Configuration find(Configuration &lst, const std::string &dotpath, const T &val)
Return dictionary in given list if it value at dotpath matches.
std::vector< int > peaks
Definition: PMTNoiseROI.h:52
bool merge_ROI(PMTNoiseROI &ROI)
float get_average_uwires_peak_height(int group)
Definition: PMTNoiseROI.cxx:90
std::vector< std::vector< int > > sorted_ind_uwires
Definition: PMTNoiseROI.h:65
std::vector< int > sorted_col_wwires
Definition: PMTNoiseROI.h:67
std::vector< int > induction_uwires
Definition: PMTNoiseROI.h:61
static int max(int a, int b)
Definition: Main.h:22
std::vector< int > collection_wwires
Definition: PMTNoiseROI.h:63
std::vector< int > & get_peaks()
Definition: PMTNoiseROI.h:23
void insert_vwires(int wire_no, float peak_height)
Definition: PMTNoiseROI.cxx:37
std::map< int, float > vwires_peak_heights
Definition: PMTNoiseROI.h:57
float get_average_vwires_peak_height(int group)
std::vector< int > & get_wwires()
Definition: PMTNoiseROI.h:27
float get_max_uwires_peak_height(int group)
Definition: PMTNoiseROI.cxx:68
PMTNoiseROI(int start_bin, int end_bin, int peak, int channel, float peak_height)
Definition: PMTNoiseROI.cxx:10