9 ROI_formation::ROI_formation(
Waveform::ChannelMaskMap& cmm,
int nwire_u,
int nwire_v,
int nwire_w,
int nbins,
float th_factor_ind,
float th_factor_col,
int pad,
float asy,
int rebin ,
double l_factor,
double l_max_th,
double l_factor1,
int l_short_length,
int l_jump_one_bin)
14 , th_factor_ind(th_factor_ind)
15 , th_factor_col(th_factor_col)
21 , l_factor1(l_factor1)
22 , l_short_length(l_short_length)
23 , l_jump_one_bin(l_jump_one_bin)
37 for (
auto it = cmm[
"bad"].
begin(); it!=cmm[
"bad"].end(); it++){
39 std::vector<std::pair<int,int>> temps;
41 for (
size_t ind = 0; ind < it->second.size(); ind++){
42 bad_ch_map[ch].push_back(std::make_pair(it->second.at(ind).first, it->second.at(ind).second));
53 for (
int irow = 0 ; irow != r_data.rows(); irow++){
58 std::vector<std::pair<int,int> > rois;
65 for (
auto it = rois.begin(); it!= rois.end(); it++){
66 int start_bin = it->first;
67 int end_bin = it->second;
69 float start_content = r_data(irow,start_bin);
70 float end_content = r_data(irow,end_bin);
71 for (
int i=start_bin; i<end_bin+1; i++){
72 int content = r_data(irow,i) - ((end_content - start_content)*(i-start_bin)/(end_bin-start_bin) + start_content);
73 signal.at(i) = content;
77 for (
int icol = 0; icol!=r_data.cols();icol++){
78 r_data(irow,icol) = signal.at(icol);
82 for (
int irow = 0 ; irow != r_data.rows(); irow++){
86 std::vector<std::pair<int,int> > rois;
94 for (
auto it = rois.begin(); it!= rois.end(); it++){
95 int start_bin = it->first;
96 int end_bin = it->second;
98 float start_content = r_data(irow,start_bin);
99 float end_content = r_data(irow,end_bin);
100 for (
int i=start_bin; i<end_bin+1; i++){
101 int content = r_data(irow,i) - ((end_content - start_content)*(i-start_bin)/(end_bin-start_bin) + start_content);
102 signal.at(i) = content;
106 for (
int icol = 0; icol!=r_data.cols();icol++){
107 r_data(irow,icol) = signal.at(icol);
111 for (
int irow = 0 ; irow != r_data.rows(); irow++){
114 std::vector<std::pair<int,int> > rois;
122 for (
auto it = rois.begin(); it!= rois.end(); it++){
123 int start_bin = it->first;
124 int end_bin = it->second;
126 for (
int i=start_bin; i<end_bin+1; i++){
127 int content = r_data(irow,i);
128 signal.at(i) = content;
132 for (
int icol = 0; icol!=r_data.cols();icol++){
133 r_data(irow,icol) = signal.at(icol);
164 std::vector<std::pair<int,int>> temp_rois;
165 int temp_begin=0, temp_end=0;
168 if (temp_begin < 0 ) temp_begin = 0;
172 if (temp_rois.size() == 0){
173 temp_rois.push_back(std::make_pair(temp_begin,temp_end));
175 if (temp_begin < temp_rois.back().second){
176 if (temp_end > temp_rois.back().second){
177 temp_rois.back().second = temp_end;
180 temp_rois.push_back(std::make_pair(temp_begin,temp_end));
188 std::vector<std::pair<int,int>> temp_rois;
189 int temp_begin=0, temp_end=0;
192 if (temp_begin < 0 ) temp_begin = 0;
196 if (temp_rois.size() == 0){
197 temp_rois.push_back(std::make_pair(temp_begin,temp_end));
199 if (temp_begin < temp_rois.back().second){
200 if (temp_end > temp_rois.back().second){
201 temp_rois.back().second = temp_end;
204 temp_rois.push_back(std::make_pair(temp_begin,temp_end));
212 std::vector<std::pair<int,int>> temp_rois;
213 int temp_begin=0, temp_end=0;
216 if (temp_begin < 0 ) temp_begin = 0;
220 if (temp_rois.size() == 0){
221 temp_rois.push_back(std::make_pair(temp_begin,temp_end));
223 if (temp_begin < temp_rois.back().second){
224 if (temp_end > temp_rois.back().second){
225 temp_rois.back().second = temp_end;
228 temp_rois.push_back(std::make_pair(temp_begin,temp_end));
242 for (
int i=0;i!=
nwire_u-2;i++){
246 int length1 = end1-start1+1;
250 int length2 = end2 - start2 + 1;
251 if ( fabs(length2 - length1) < (length2 + length1) *
asy){
252 int start3 = (start1+start2)/2.;
253 int end3 = (end1+end2)/2.;
254 if (start3 < end3 && start3 <= end1 && start3 <=end2 && end3 >= start1 && end3 >=start2){
257 for (
size_t i1 = 0; i1!=
self_rois_u.at(i+1).size();i1++){
258 int max_start = start3;
264 if (max_start < min_end){
270 self_rois_u.at(i+1).push_back(std::make_pair(start3,end3));
278 for (
int i=0;i!=
nwire_v-2;i++){
282 int length1 = end1-start1+1;
286 int length2 = end2 - start2 + 1;
287 if ( fabs(length2 - length1) < (length2 + length1) *
asy){
288 int start3 = (start1+start2)/2.;
289 int end3 = (end1+end2)/2.;
290 if (start3 < end3 && start3 <= end1 && start3 <=end2 && end3 >= start1 && end3 >=start2){
293 for (
size_t i1 = 0; i1!=
self_rois_v.at(i+1).size();i1++){
294 int max_start = start3;
300 if (max_start < min_end){
306 self_rois_v.at(i+1).push_back(std::make_pair(start3,end3));
314 for (
int i=0;i!=
nwire_w-2;i++){
318 int length1 = end1-start1+1;
322 int length2 = end2 - start2 + 1;
323 if ( fabs(length2 - length1) < (length2 + length1) *
asy){
324 int start3 = (start1+start2)/2.;
325 int end3 = (end1+end2)/2.;
326 if (start3 < end3 && start3 <= end1 && start3 <=end2 && end3 >= start1 && end3 >=start2){
329 for (
size_t i1 = 0; i1!=
self_rois_w.at(i+1).size();i1++){
330 int max_start = start3;
336 if (max_start < min_end){
342 self_rois_w.at(i+1).push_back(std::make_pair(start3,end3));
353 if (signal.size()>0){
359 float rms = sqrt((
pow(par[2]-par[1],2)+
pow(par[1]-par[0],2))/2.);
363 for(
size_t i =0; i!=signal.size();i++){
364 if (fabs(signal.at(i)) < 5.0 * rms){
365 rms1 +=
pow(signal.at(i),2);
370 result = sqrt(rms1/rms2);
388 for (
int irow = 0; irow!=r_data.rows(); irow++){
396 for (
int icol=0;icol!=r_data.cols();icol++){
398 for (
size_t i=0; i!=
bad_ch_map[irow+offset].size(); i++){
399 if (icol >=
bad_ch_map[irow+offset].at(i).first &&
400 icol <=
bad_ch_map[irow+offset].at(i).second){
406 signal.at(ncount) = r_data(irow,icol);
407 signal1.at(icol) = r_data(irow,icol);
408 signal2.at(icol) = r_data_tight(irow,icol);
411 signal1.at(icol) = 0;
412 signal2.at(icol) = 0;
415 signal.resize(ncount);
417 for (
int icol = 0; icol!= r_data.cols(); icol++){
418 signal.at(icol) = r_data(irow,icol);
419 signal1.at(icol) = r_data(irow,icol);
420 signal2.at(icol) = r_data_tight(irow,icol);
425 double threshold = 0;
443 std::vector<std::pair<int,int>> temp_rois;
445 for (
int j=0;j<
int(signal1.size())-1;j++){
446 double content = signal1.at(j);
447 double content_tight = signal2.at(j);
449 if (content > threshold ||
450 (content_tight > threshold )){
453 for (
int k=j+1;
k<
int(signal1.size());
k++){
454 if (signal1.at(
k) > threshold ||
455 (signal2.at(
k) > threshold)){
461 int temp_roi_begin = roi_begin ;
462 if (temp_roi_begin <0 ) temp_roi_begin = 0;
463 int temp_roi_end = roi_end ;
464 if (temp_roi_end >
int(signal1.size())-1) temp_roi_end =
int(signal1.size())-1;
469 if (temp_rois.size() == 0){
470 temp_rois.push_back(std::make_pair(temp_roi_begin,temp_roi_end));
472 if (temp_roi_begin <= temp_rois.back().second){
473 temp_rois.back().second = temp_roi_end;
475 temp_rois.push_back(std::make_pair(temp_roi_begin,temp_roi_end));
520 std::vector<std::pair<int,int>> temp_rois;
527 if (start > temp_start && start < temp_end)
530 if (end > temp_start && end < temp_end)
534 if (temp_rois.size()==0){
535 temp_rois.push_back(std::make_pair(start,end));
537 if (start < temp_rois.back().second){
538 temp_rois.back().second =
end;
540 temp_rois.push_back(std::make_pair(start,end));
548 std::vector<std::pair<int,int>> temp_rois;
555 if (start > temp_start && start < temp_end)
558 if (end > temp_start && end < temp_end)
562 if (temp_rois.size()==0){
563 temp_rois.push_back(std::make_pair(start,end));
565 if (start < temp_rois.back().second){
566 temp_rois.back().second =
end;
568 temp_rois.push_back(std::make_pair(start,end));
583 for (
int i=-width;i<width+1;i++){
584 int current_bin = bin + i;
586 while (current_bin <0)
587 current_bin += signal.size();
588 while (current_bin >=
int(signal.size()))
589 current_bin -= signal.size();
591 sum1 += signal.at(current_bin);
605 double content = signal.at(end);
608 if (end >=
int(signal.size())){
609 content = signal.at(end-signal.size());
611 content = signal.at(end);
613 if (end >=
int(signal.size())-1) {
614 end =
int(signal.size())-1;
624 if (end >=
int(signal.size())-1) {
625 end =
int(signal.size())-1;
635 double content = signal.at(begin);
639 content = signal.at(begin +
int(signal.size()));
641 content = signal.at(begin);
679 for (
int irow =0; irow!=r_data.rows();irow++){
688 for (
int icol=0;icol!=r_data.cols();icol++){
690 for (
size_t i=0; i!=
bad_ch_map[irow+offset].size(); i++){
691 if (icol >=
bad_ch_map[irow+offset].at(i).first &&
692 icol <=
bad_ch_map[irow+offset].at(i).second){
698 signal.at(ncount) = r_data(irow,icol);
699 signal1.at(icol) = r_data(irow,icol);
702 signal1.at(icol) = 0;
705 signal.resize(ncount);
707 for (
int icol = 0; icol!= r_data.cols(); icol++){
708 signal.at(icol) = r_data(irow,icol);
709 signal1.at(icol) = r_data(irow,icol);
716 for (
size_t i=0;i!=signal2.size();i++){
718 for (
int j=0;j!=
rebin;j++){
719 temp += signal1.at(
rebin * i + j);
721 signal2.at(i) = temp;
732 std::vector<std::pair <int,int> > ROIs_1;
733 std::vector<int> max_bins_1;
734 int ntime = signal2.size();
742 for (
int j=1; j<ntime-1;j++){
743 double content = signal2.at(j);
744 double prev_content = signal2.at(j-1);
745 double next_content = signal2.at(j+1);
755 for (
int k=begin;
k<=
end;
k++){
757 if (signal2.at(
k) > signal2.at(max_bin)){
763 if (content > prev_content && content > next_content){
767 for (
int k=begin;
k<=
end;
k++){
768 if (signal2.at(
k) > signal2.at(max_bin)){
772 if (signal2.at(max_bin) - signal2.at(begin) + signal2.at(max_bin) - signal2.at(end) > th * 2){
778 if (temp_begin < begin) temp_begin =
begin;
780 if (temp_end > end) temp_end =
end;
781 if ((signal2.at(max_bin) - signal2.at(temp_begin) > th *
l_factor1 &&
782 signal2.at(max_bin) - signal2.at(temp_end) > th *
l_factor1)){
805 if (ROIs_1.size()>0){
806 if (begin <= ROIs_1.back().second){
807 ROIs_1.back().second =
end;
808 if (signal2.at(max_bin) > signal2.at(max_bins_1.back()))
809 max_bins_1.back() = max_bin;
811 ROIs_1.push_back(std::make_pair(begin,end));
812 max_bins_1.push_back(max_bin);
815 ROIs_1.push_back(std::make_pair(begin,end));
816 max_bins_1.push_back(max_bin);
819 if (end <
int(signal2.size())){
838 if (ROIs_1.size()==1){
839 }
else if (ROIs_1.size()>1){
844 for (
int k=0;
k<
int(ROIs_1.size()-1);
k++){
845 int begin = ROIs_1.at(
k).first;
846 int end = ROIs_1.at(
k+1).second;
848 double begin_content = signal2.at(begin);
849 double end_content = signal2.at(end);
851 int begin_1 = ROIs_1.at(
k).second;
852 int end_1 = ROIs_1.at(
k+1).first;
856 for (
int j=begin_1; j<=end_1;j++){
857 double current_content = signal2.at(j);
858 double content = current_content - ((end_content - begin_content)*(j*1.-begin)/(end-begin*1.) + begin_content);
872 if (flag_merge == 1){
873 ROIs_1.at(
k).second = ROIs_1.at(
k+1).second;
874 ROIs_1.erase(ROIs_1.begin()+
k+1);
886 for (
int j = 0; j!=
int(ROIs_1.size());j++){
890 ROIs_1.at(j).first =
begin;
891 ROIs_1.at(j).second =
end;
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
QTextStream & bin(QTextStream &s)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Eigen::ArrayXXf array_xxf
A real, 2D array.