9 ROI_refinement::ROI_refinement(
Waveform::ChannelMaskMap& cmm,
int nwire_u,
int nwire_v,
int nwire_w,
float th_factor,
float fake_signal_low_th,
float fake_signal_high_th,
float fake_signal_low_th_ind_factor,
float fake_signal_high_th_ind_factor,
int pad,
int break_roi_loop,
float th_peak,
float sep_peak,
float low_peak_sep_threshold_pre,
int max_npeaks,
float sigma,
float th_percent)
13 , th_factor(th_factor)
14 , fake_signal_low_th(fake_signal_low_th)
15 , fake_signal_high_th(fake_signal_high_th)
16 , fake_signal_low_th_ind_factor(fake_signal_low_th_ind_factor)
17 , fake_signal_high_th_ind_factor(fake_signal_high_th_ind_factor)
19 , break_roi_loop(break_roi_loop)
22 , low_peak_sep_threshold_pre(low_peak_sep_threshold_pre)
23 , max_npeaks(max_npeaks)
25 , th_percent(th_percent)
26 , log(Log::
logger(
"sigproc"))
58 for (
auto it = cmm[
"bad"].
begin(); it!=cmm[
"bad"].end(); it++){
60 std::vector<std::pair<int,int>> temps;
62 for (
size_t ind = 0; ind < it->second.size(); ind++){
63 bad_ch_map[ch].push_back(std::make_pair(it->second.at(ind).first, it->second.at(ind).second));
111 for (
int irow = 0 ; irow != r_data.rows(); irow++){
123 float start_content = r_data(irow,start_bin);
124 float end_content = r_data(irow,end_bin);
125 for (
int i=start_bin; i<end_bin+1; i++){
126 int content = r_data(irow,i) - ((end_content - start_content)*(i-start_bin)/(end_bin-start_bin) + start_content);
127 signal.at(i) = content;
132 for (
int icol = 0; icol!=r_data.cols();icol++){
133 r_data(irow,icol) = signal.at(icol);
137 for (
int irow = 0 ; irow != r_data.rows(); irow++){
149 float start_content = r_data(irow,start_bin);
150 float end_content = r_data(irow,end_bin);
151 for (
int i=start_bin; i<end_bin+1; i++){
152 int content = r_data(irow,i) - ((end_content - start_content)*(i-start_bin)/(end_bin-start_bin) + start_content);
153 signal.at(i) = content;
158 for (
int icol = 0; icol!=r_data.cols();icol++){
159 r_data(irow,icol) = signal.at(icol);
163 for (
int irow = 0 ; irow != r_data.rows(); irow++){
188 for (
int i=start_bin; i<end_bin+1; i++){
189 int content = r_data(irow,i);
190 signal.at(i) = content;
194 for (
int icol = 0; icol!=r_data.cols();icol++){
195 r_data(irow,icol) = signal.at(icol);
212 auto it =
find(temp_rois.begin(),temp_rois.end(),next_roi);
213 if (it != temp_rois.end())
218 auto it =
find(temp_rois.begin(),temp_rois.end(),prev_roi);
219 if (it != temp_rois.end())
227 auto it =
find(temp_rois.begin(),temp_rois.end(),next_roi);
228 if (it == temp_rois.end())
229 temp_rois.push_back(next_roi);
232 temp_rois.push_back(next_roi);
238 auto it =
find(temp_rois.begin(),temp_rois.end(),prev_roi);
239 if (it == temp_rois.end())
240 temp_rois.push_back(prev_roi);
243 temp_rois.push_back(prev_roi);
250 std::vector<float> plane_rms;
264 for (
int irow = 0; irow!=r_data.rows(); irow++){
267 for (
int icol=0;icol!=r_data.cols();icol++){
269 for (
size_t i=0; i!=
bad_ch_map[irow+offset].size(); i++){
270 if (icol >=
bad_ch_map[irow+offset].at(i).first &&
271 icol <=
bad_ch_map[irow+offset].at(i).second){
277 signal.at(icol) = r_data(irow,icol);
283 for (
int icol = 0; icol!= r_data.cols(); icol++){
284 signal.at(icol) = r_data(irow,icol);
288 int chid = irow+offset;
290 std::vector<std::pair<int,int>>& uboone_rois = roi_form.
get_self_rois(irow+offset);
291 for (
size_t i=0;i!=uboone_rois.size();i++){
292 SignalROI *tight_roi =
new SignalROI(plane,irow+offset, uboone_rois.at(i).first,uboone_rois.at(i).second, signal);
293 float threshold = plane_rms.at(irow) *
th_factor;
305 if (tight_roi->
overlap(prev_roi)){
308 temp_rois.push_back(tight_roi);
315 temp_rois.push_back(prev_roi);
318 back_rois[tight_roi].push_back(prev_roi);
327 if (tight_roi->
overlap(next_roi)){
330 temp_rois.push_back(tight_roi);
333 back_rois[next_roi].push_back(tight_roi);
338 temp_rois.push_back(next_roi);
352 if (tight_roi->
overlap(prev_roi)){
355 temp_rois.push_back(tight_roi);
362 temp_rois.push_back(prev_roi);
365 back_rois[tight_roi].push_back(prev_roi);
375 if (tight_roi->
overlap(next_roi)){
378 temp_rois.push_back(tight_roi);
381 back_rois[next_roi].push_back(tight_roi);
385 temp_rois.push_back(next_roi);
400 if (tight_roi->
overlap(prev_roi)){
403 temp_rois.push_back(tight_roi);
410 temp_rois.push_back(prev_roi);
413 back_rois[tight_roi].push_back(prev_roi);
424 if (tight_roi->
overlap(next_roi)){
427 temp_rois.push_back(tight_roi);
430 back_rois[next_roi].push_back(tight_roi);
434 temp_rois.push_back(next_roi);
450 for (
size_t i = 0; i!=uboone_rois.size();i++){
451 SignalROI *loose_roi =
new SignalROI(plane,chid,uboone_rois.at(i).first,uboone_rois.at(i).second,signal);
452 float threshold = plane_rms.at(irow) *
th_factor;
464 if (loose_roi->
overlap(prev_roi)){
467 temp_rois.push_back(loose_roi);
474 temp_rois.push_back(prev_roi);
477 back_rois[loose_roi].push_back(prev_roi);
487 if (loose_roi->
overlap(next_roi)){
490 temp_rois.push_back(loose_roi);
493 back_rois[next_roi].push_back(loose_roi);
497 temp_rois.push_back(next_roi);
509 if (tight_roi->
overlap(loose_roi)){
512 temp_rois.push_back(tight_roi);
530 if (loose_roi->
overlap(prev_roi)){
533 temp_rois.push_back(loose_roi);
540 temp_rois.push_back(prev_roi);
543 back_rois[loose_roi].push_back(prev_roi);
553 if (loose_roi->
overlap(next_roi)){
556 temp_rois.push_back(loose_roi);
559 back_rois[next_roi].push_back(loose_roi);
563 temp_rois.push_back(next_roi);
575 if (tight_roi->
overlap(loose_roi)){
578 temp_rois.push_back(tight_roi);
596 std::map<SignalROI*, int> ROIsaved_map;
604 if (ROIsaved_map.find(roi)==ROIsaved_map.end()){
608 temp_rois.push_back(roi);
609 ROIsaved_map[roi] = 1;
611 while(temp_rois.size()){
613 temp_rois.pop_back();
617 if (ROIsaved_map.find(*it1)==ROIsaved_map.end()){
618 temp_rois.push_back(*it1);
619 ROIsaved_map[*it1] = 1;
625 if (ROIsaved_map.find(*it1)==ROIsaved_map.end()){
626 temp_rois.push_back(*it1);
627 ROIsaved_map[*it1] = 1;
643 if (ROIsaved_map.find(roi) == ROIsaved_map.end()){
645 to_be_removed.push_back(roi);
670 for (
auto it = to_be_removed.begin(); it!= to_be_removed.end(); it++){
683 if (ROIsaved_map.find(roi)==ROIsaved_map.end()){
687 temp_rois.push_back(roi);
688 ROIsaved_map[roi] = 1;
690 while(temp_rois.size()){
692 temp_rois.pop_back();
696 if (ROIsaved_map.find(*it1)==ROIsaved_map.end()){
697 temp_rois.push_back(*it1);
698 ROIsaved_map[*it1] = 1;
704 if (ROIsaved_map.find(*it1)==ROIsaved_map.end()){
705 temp_rois.push_back(*it1);
706 ROIsaved_map[*it1] = 1;
722 if (ROIsaved_map.find(roi) == ROIsaved_map.end()){
724 to_be_removed.push_back(roi);
749 for (
auto it = to_be_removed.begin(); it!= to_be_removed.end(); it++){
770 for (
int i = 0;i!=
nwire_u;i++){
771 std::map<SignalROI*,int> covered_tight_rois;
776 if (covered_tight_rois.find(*it1)==covered_tight_rois.end()){
777 covered_tight_rois[*it1] =1;
785 if (covered_tight_rois.find(roi) == covered_tight_rois.end()){
786 saved_rois.push_back(roi);
792 for (
auto it = saved_rois.begin(); it!=saved_rois.end();it++){
802 temp_rois.push_back(roi);
809 if (loose_roi->
overlap(next_roi)){
812 temp_rois.push_back(loose_roi);
815 back_rois[next_roi].push_back(loose_roi);
820 temp_rois.push_back(next_roi);
833 if (loose_roi->
overlap(prev_roi)){
836 temp_rois.push_back(loose_roi);
843 temp_rois.push_back(prev_roi);
846 back_rois[loose_roi].push_back(prev_roi);
854 for (
int i = 0;i!=
nwire_v;i++){
855 std::map<SignalROI*,int> covered_tight_rois;
860 if (covered_tight_rois.find(*it1)==covered_tight_rois.end()){
861 covered_tight_rois[*it1] =1;
869 if (covered_tight_rois.find(roi) == covered_tight_rois.end()){
870 saved_rois.push_back(roi);
877 for (
auto it = saved_rois.begin(); it!=saved_rois.end();it++){
887 temp_rois.push_back(roi);
894 if (loose_roi->
overlap(next_roi)){
897 temp_rois.push_back(loose_roi);
900 back_rois[next_roi].push_back(loose_roi);
905 temp_rois.push_back(next_roi);
918 if (loose_roi->
overlap(prev_roi)){
921 temp_rois.push_back(loose_roi);
928 temp_rois.push_back(prev_roi);
931 back_rois[loose_roi].push_back(prev_roi);
980 if (roi->
overlap(roi1,th,th1)){
982 temp_rois.push_back(roi1);
986 for (
auto it2 = temp_rois.begin(); it2!= temp_rois.end();it2++){
999 if (roi->
overlap(roi1,th,th1)){
1001 temp_rois.push_back(roi1);
1005 for (
auto it2 = temp_rois.begin(); it2!= temp_rois.end();it2++){
1012 }
else if (plane==1){
1028 if (roi->
overlap(roi1,th,th1)){
1030 temp_rois.push_back(roi1);
1034 for (
auto it2 = temp_rois.begin(); it2!= temp_rois.end();it2++){
1046 if (roi->
overlap(roi1,th,th1)){
1048 temp_rois.push_back(roi1);
1052 for (
auto it2 = temp_rois.begin(); it2!= temp_rois.end();it2++){
1066 std::set<SignalROI*> Good_ROIs;
1072 Good_ROIs.insert(roi);
1076 std::list<SignalROI*> Bad_ROIs;
1081 if (Good_ROIs.find(roi)!=Good_ROIs.end())
continue;
1085 for (
size_t i=0;i!=next_rois.size();i++){
1087 if (Good_ROIs.find(roi1)!=Good_ROIs.end()) {
1092 if (flag_qx == 1)
continue;
1098 for (
size_t i=0;i!=next_rois.size();i++){
1100 if (Good_ROIs.find(roi1)!=Good_ROIs.end()) {
1105 if (flag_qx == 1)
continue;
1108 Bad_ROIs.push_back(roi);
1114 for (
auto it = Bad_ROIs.begin(); it!=Bad_ROIs.end(); it ++){
1120 for (
size_t i=0;i!=next_rois.size();i++){
1122 unlink(roi,next_rois.at(i));
1129 for (
size_t i=0;i!=prev_rois.size();i++){
1131 unlink(prev_rois.at(i),roi);
1152 std::list<SignalROI*> Bad_ROIs;
1160 Bad_ROIs.push_back(roi);
1164 for (
auto it = Bad_ROIs.begin(); it!=Bad_ROIs.end(); it ++){
1173 for (
size_t i=0;i!=next_rois.size();i++){
1175 unlink(roi,next_rois.at(i));
1182 for (
size_t i=0;i!=prev_rois.size();i++){
1184 unlink(prev_rois.at(i),roi);
1192 }
else if (plane==1){
1199 Bad_ROIs.push_back(roi);
1203 for (
auto it = Bad_ROIs.begin(); it!=Bad_ROIs.end(); it ++){
1212 for (
size_t i=0;i!=next_rois.size();i++){
1214 unlink(roi,next_rois.at(i));
1221 for (
size_t i=0;i!=prev_rois.size();i++){
1223 unlink(prev_rois.at(i),roi);
1235 std::set<SignalROI*> Good_ROIs;
1241 Good_ROIs.insert(roi);
1249 if (Good_ROIs.find(roi)!=Good_ROIs.end())
continue;
1253 for (
size_t i=0;i!=next_rois.size();i++){
1255 if (Good_ROIs.find(roi1)!=Good_ROIs.end()) {
1260 if (flag_qx == 1)
continue;
1266 for (
size_t i=0;i!=next_rois.size();i++){
1268 if (Good_ROIs.find(roi1)!=Good_ROIs.end()) {
1273 if (flag_qx == 1)
continue;
1276 Bad_ROIs.push_back(roi);
1279 for (
auto it = Bad_ROIs.begin(); it!=Bad_ROIs.end(); it ++){
1285 for (
size_t i=0;i!=next_rois.size();i++){
1287 unlink(roi,next_rois.at(i));
1294 for (
size_t i=0;i!=prev_rois.size();i++){
1296 unlink(prev_rois.at(i),roi);
1306 }
else if (plane==1){
1313 Good_ROIs.insert(roi);
1321 if (Good_ROIs.find(roi)!=Good_ROIs.end())
continue;
1325 for (
size_t i=0;i!=next_rois.size();i++){
1327 if (Good_ROIs.find(roi1)!=Good_ROIs.end()) {
1332 if (flag_qx == 1)
continue;
1338 for (
size_t i=0;i!=next_rois.size();i++){
1340 if (Good_ROIs.find(roi1)!=Good_ROIs.end()) {
1345 if (flag_qx == 1)
continue;
1348 Bad_ROIs.push_back(roi);
1351 for (
auto it = Bad_ROIs.begin(); it!=Bad_ROIs.end(); it ++){
1357 for (
size_t i=0;i!=next_rois.size();i++){
1359 unlink(roi,next_rois.at(i));
1366 for (
size_t i=0;i!=prev_rois.size();i++){
1368 unlink(prev_rois.at(i),roi);
1386 if (start_bin <0 || end_bin <0)
return;
1395 }
else if (plane==1){
1399 int channel_save = 1240;
1414 if (chid == channel_save && print_flag)
1415 std::cout <<
"Tight " " " << start_bin1 <<
" " << end_bin1 <<
std::endl;
1417 for (
int i=start_bin1;i<=end_bin1;i++){
1418 if (i-start_bin >=0 && i-start_bin <
int(temp_signal.size())){
1420 temp_signal.at(i-start_bin) = 1;
1438 }
else if (plane1==1){
1441 std::vector<std::pair<int,int>> contents_above_threshold = next_roi->
get_above_threshold(threshold);
1442 for (
size_t i=0;i!=contents_above_threshold.size();i++){
1443 if (chid == channel_save && print_flag)
1444 std::cout <<
"Front " << chid1 <<
" " << start_bin1 + contents_above_threshold.at(i).first <<
" " << start_bin1 + contents_above_threshold.at(i).second <<
std::endl;
1446 for (
int j=contents_above_threshold.at(i).first;j<=contents_above_threshold.at(i).second;j++){
1447 if (j+start_bin1-start_bin >=0 && j+start_bin1-start_bin <
int(temp_signal.size())){
1448 if (contents.at(j+start_bin1-start_bin) > threshold1)
1449 temp_signal.at(j+start_bin1-start_bin) = 1;
1466 float threshold = 0;
1469 }
else if (plane1==1){
1472 std::vector<std::pair<int,int>> contents_above_threshold = prev_roi->
get_above_threshold(threshold);
1473 for (
size_t i=0;i!=contents_above_threshold.size();i++){
1474 if (chid == channel_save && print_flag)
1475 std::cout <<
"Back " << chid1 <<
" " << start_bin1 + contents_above_threshold.at(i).first <<
" " << start_bin1 + contents_above_threshold.at(i).second <<
std::endl;
1477 for (
int j=contents_above_threshold.at(i).first;j<=contents_above_threshold.at(i).second;j++){
1478 if (j+start_bin1-start_bin >=0 && j+start_bin1-start_bin <
int(temp_signal.size())){
1479 if (contents.at(j+start_bin1-start_bin) > threshold1)
1480 temp_signal.at(j+start_bin1-start_bin) = 1;
1501 int new_start_bin=start_bin;
1502 int new_end_bin=end_bin;
1503 for (
size_t i=0;i!= temp_signal.size(); i++){
1504 if (temp_signal.at(i) >0){
1505 new_start_bin = i + start_bin;
1509 for (
int i =
int(temp_signal.size())-1;i>=0;i--){
1510 if (temp_signal.at(i) > 0){
1511 new_end_bin = i + start_bin;
1515 new_start_bin -=
pad;
1517 if (new_start_bin < start_bin) new_start_bin = start_bin;
1518 if (new_end_bin > end_bin) new_end_bin = end_bin;
1520 if (chid == channel_save && print_flag)
1521 std::cout <<
"check contents " <<
" " << start_bin <<
" " << end_bin <<
" " << new_start_bin <<
" " << new_end_bin <<
std::endl;
1527 for (
int i=new_start_bin; i<=new_end_bin;i++){
1528 signal.at(i) = contents.at(i-start_bin);
1533 if (new_start_bin >=0 && new_end_bin > new_start_bin){
1535 new_rois.push_back(new_roi);
1544 for (
size_t i=0;i!=new_rois.size();i++){
1550 for (
size_t i=0;i!=new_rois.size();i++){
1559 for (
size_t i=0;i!=next_rois.size();i++){
1561 unlink(roi,next_rois.at(i));
1563 for (
size_t j=0;j!=new_rois.size();j++){
1564 if (new_rois.at(j)->overlap(next_rois.at(i)))
1565 link(new_rois.at(j),next_rois.at(i));
1573 for (
size_t i=0;i!=prev_rois.size();i++){
1575 unlink(prev_rois.at(i),roi);
1577 for (
size_t j=0;j!=new_rois.size();j++){
1578 if (new_rois.at(j)->overlap(prev_rois.at(i)))
1579 link(prev_rois.at(i),new_rois.at(j));
1588 for (
size_t i=0;i!=tight_rois.size();i++){
1589 for (
size_t j=0;j!=new_rois.size();j++){
1590 if (new_rois.at(j)->overlap(tight_rois.at(i))){
1593 temp_rois.push_back(tight_rois.at(i));
1617 all_rois.push_back(*it);
1620 }
else if (plane==1){
1623 all_rois.push_back(*it);
1627 for (
size_t i=0;i!=all_rois.size();i++){
1640 if (start_bin <0 || end_bin <0 )
return;
1649 for (
size_t i=0;i!=temp_signal.size();i++){
1650 temp_signal.at(i) = contents.at(i);
1657 if (low_peak_sep_threshold <
sep_peak * rms)
1659 std::set<int> saved_boundaries;
1662 const int nfound = s.
find_peak(temp_signal);
1667 log->debug(
"ROI_refinement: local ch index {} (plane {}), found max peaks {} with threshold={}",
1676 std::vector<int> order_peak_pos;
1677 int npeaks_threshold = 0;
1678 for (
int j=0;j!=npeaks;j++){
1679 order_peak_pos.push_back(*(peak_pos+j) + start_bin);
1680 if (*(peak_height+j)>
th_peak*rms){
1681 npeaks_threshold ++;
1687 if (npeaks_threshold >1){
1688 std::sort(order_peak_pos.begin(),order_peak_pos.end());
1689 float valley_pos[205];
1690 valley_pos[0] = start_bin;
1694 for (
int k=0;
k< order_peak_pos[0]-start_bin;
k++){
1695 if (temp_signal.at(
k) <
min){
1696 min = temp_signal.at(
k);
1697 valley_pos[0] =
k+start_bin;
1700 if (valley_pos[0] != start_bin){
1702 order_peak_pos.push_back(0);
1704 for (
int j=npeaks-1;j>=0;j--){
1705 order_peak_pos[j+1] = order_peak_pos[j];
1708 order_peak_pos[0] = start_bin;
1709 for (
int j=start_bin; j!=valley_pos[0];j++){
1710 if (temp_signal.at(j-start_bin) > temp_signal.at(order_peak_pos[0]-start_bin))
1712 order_peak_pos[0] = j;
1714 valley_pos[0] = start_bin;
1719 for (
int j=0;j!=npeaks-1;j++){
1721 valley_pos[j+1] = order_peak_pos[j];
1725 for (
int k = order_peak_pos[j]-start_bin;
k< order_peak_pos[j+1]-start_bin;
k++){
1726 if (temp_signal.at(
k) <
min){
1727 min = temp_signal.at(
k);
1728 valley_pos[j+1] =
k+start_bin;
1736 valley_pos[npeaks] = end_bin;
1738 for (
int k=order_peak_pos[npeaks-1]-start_bin;
k<= end_bin-start_bin;
k++){
1739 if (temp_signal.at(
k) <
min){
1740 min = temp_signal.at(
k);
1741 valley_pos[npeaks] =
k+start_bin;
1747 if (valley_pos[npeaks]!=end_bin){
1749 valley_pos[npeaks] = end_bin;
1751 order_peak_pos.push_back(end_bin);
1753 for (
int j=valley_pos[npeaks-1];j!=valley_pos[npeaks];j++){
1754 if (temp_signal.at(j-start_bin) > temp_signal.at(order_peak_pos[npeaks-1] -start_bin))
1755 order_peak_pos[npeaks-1] = j;
1770 float valley_pos1[205];
1771 float peak_pos1[205];
1774 valley_pos1[0] = valley_pos[0];
1775 for (
int j=0;j<npeaks;j++){
1779 if (temp_signal.at(valley_pos[j]-start_bin) < temp_signal.at(valley_pos1[npeaks1]-start_bin)){
1780 valley_pos1[npeaks1] = valley_pos[j];
1789 if (temp_signal.at(order_peak_pos[j]-start_bin) - temp_signal.at(valley_pos1[npeaks1]-start_bin) > low_peak_sep_threshold){
1790 peak_pos1[npeaks1] = order_peak_pos[j] ;
1794 for (
int k=j+1;
k!=npeaks+1;
k++){
1797 if (temp_signal.at(order_peak_pos[
k-1]-start_bin) > temp_signal.at(peak_pos1[npeaks1-1]-start_bin))
1798 peak_pos1[npeaks1-1] = order_peak_pos[
k-1];
1801 if (temp_signal.at(peak_pos1[npeaks1-1]-start_bin) - temp_signal.at(valley_pos[
k]-start_bin) > low_peak_sep_threshold){
1802 valley_pos1[npeaks1] = valley_pos[
k];
1810 valley_pos1[npeaks1] = valley_pos[npeaks];
1819 valley_pos1[npeaks1] = valley_pos[npeaks];
1833 for (
int j=0;j!=npeaks1;j++){
1834 int start_pos = valley_pos1[j];
1835 int end_pos = valley_pos1[j+1];
1840 saved_boundaries.insert(start_pos);
1841 saved_boundaries.insert(end_pos);
1845 temp_signal.clear();
1846 temp_signal.resize(temp1_signal.size(),0);
1848 for (
int j=0;j!=npeaks1;j++){
1850 int start_pos = valley_pos1[j];
1851 double start_content = temp1_signal.at(valley_pos1[j]-start_bin);
1852 int end_pos = valley_pos1[j+1];
1853 double end_content = temp1_signal.at(valley_pos1[j+1]-start_bin);
1857 if (saved_boundaries.find(start_pos) != saved_boundaries.end() ||
1858 saved_boundaries.find(end_pos) != saved_boundaries.end()){
1862 for (
int k = start_pos;
k!=end_pos+1;
k++){
1863 double temp_content = temp1_signal.at(
k-start_bin) - (start_content + (end_content-start_content) * (
k-start_pos) / (end_pos - start_pos));
1864 temp_signal.at(
k-start_bin) = temp_content;
1915 for (
int qx = 0; qx!=2; qx++){
1917 std::vector<std::pair<int,int>> bins;
1918 for (
int i=0;i<
int(temp_signal.size());i++){
1922 for (
int j=i+1;j<
int(temp_signal.size());j++){
1929 bins.push_back(std::make_pair(start,end));
1938 std::vector<int> saved_b;
1939 for (
int i=0;i!=
int(bins.size());i++){
1940 int start = bins.at(i).first;
1941 int end = bins.at(i).second;
1944 int bin_min = start;
1945 for (
int j=start;j<=
end;j++){
1946 if (fabs(temp_signal.at(j)) < 1
e-3){
1950 if (temp_signal.at(j) <
min){
1951 min = temp_signal.at(j);
1960 saved_b.push_back(bin_min);
1969 temp_signal.clear();
1970 temp_signal.resize(temp1_signal.size(),0);
1973 for (
int j=0;j<
int(saved_b.size())-1;j++){
1979 int start_pos = saved_b.at(j);
1980 float start_content = temp1_signal.at(start_pos);
1981 int end_pos = saved_b.at(j+1);
1982 float end_content = temp1_signal.at(end_pos);
1984 for (
int k = start_pos;
k!=end_pos+1;
k++){
1985 double temp_content = temp1_signal.at(
k) - (start_content + (end_content-start_content) * (
k-start_pos) / (end_pos - start_pos));
1986 temp_signal.at(
k) = temp_content;
1995 for (
int i=0;i!=
int(temp_signal.size());i++){
1996 contents.at(i) = temp_signal.at(i);
2007 if (start_bin <0 || end_bin < 0)
return;
2012 for (
size_t i=0;i!=temp_signal.size();i++){
2013 temp_signal.at(i) = contents.at(i);
2018 std::vector<int> bins;
2019 for (
size_t i=0;i!= temp_signal.size(); i++){
2020 if (fabs(temp_signal.at(i))<1
e-3)
2021 bins.push_back(i+start_bin);
2032 for (
int i=0;i!=
int(bins.size())-1;i++){
2033 int start_bin1 = bins.at(i);
2034 int end_bin1 = bins.at(i+1);
2038 signal.resize(end_bin+1,0);
2040 for (
int j=start_bin1;j<=end_bin1;j++){
2041 signal.at(j) = temp_signal.at(j-start_bin);
2044 if (start_bin1 >=0 && end_bin1 >start_bin1){
2046 new_rois.push_back(sub_roi);
2054 for (
size_t i=0;i!=new_rois.size();i++){
2060 for (
size_t i=0;i!=new_rois.size();i++){
2069 for (
size_t i=0;i!=next_rois.size();i++){
2071 unlink(roi,next_rois.at(i));
2073 for (
size_t j=0;j!=new_rois.size();j++){
2074 if (new_rois.at(j)->overlap(next_rois.at(i)))
2075 link(new_rois.at(j),next_rois.at(i));
2083 for (
size_t i=0;i!=prev_rois.size();i++){
2085 unlink(prev_rois.at(i),roi);
2087 for (
size_t j=0;j!=new_rois.size();j++){
2088 if (new_rois.at(j)->overlap(prev_rois.at(i)))
2089 link(prev_rois.at(i),new_rois.at(j));
2098 for (
size_t i=0;i!=tight_rois.size();i++){
2099 for (
size_t j=0;j!=new_rois.size();j++){
2100 if (new_rois.at(j)->overlap(tight_rois.at(i))){
2103 temp_rois.push_back(tight_rois.at(i));
2129 all_rois.push_back(*it);
2133 }
else if (plane==1){
2138 all_rois.push_back(*it);
2144 for (
size_t i=0;i!=all_rois.size();i++){
2206 if (cmd==
"CleanUpROIs") {
2213 else if (cmd==
"BreakROIs") {
2221 else if (cmd==
"ShrinkROIs") {
2229 else if (cmd==
"ExtendROIs") {
2246 for (
int chid = 0; chid !=
nwire_u; chid ++){
2253 std::cout << chid <<
" u " << +1 <<
" " << roi <<
" " << roi1 <<
std::endl;
2260 std::cout << chid <<
" u " << -1 <<
" " << roi <<
" " << roi1 <<
std::endl;
2266 for (
int chid = 0; chid !=
nwire_v; chid ++){
2273 std::cout << chid <<
" v " << +1 <<
" " << roi <<
" " << roi1 <<
std::endl;
2280 std::cout << chid <<
" v " << -1 <<
" " << roi <<
" " << roi1 <<
std::endl;
2285 for (
int chid = 0; chid !=
nwire_w; chid ++){
2292 std::cout << chid <<
" w " << +1 <<
" " << roi <<
" " << roi1 <<
std::endl;
2299 std::cout << chid <<
" w " << -1 <<
" " << roi <<
" " << roi1 <<
std::endl;
2311 for (
int chid = 0; chid !=
nwire_u; chid ++){
2326 if (ext_end_bin < roi1->get_end_bin()) ext_end_bin = roi1->
get_end_bin();
2338 if (ext_end_bin < roi1->get_end_bin()) ext_end_bin = roi1->
get_end_bin();
2366 for (
int chid = 0; chid !=
nwire_v; chid ++){
2381 if (ext_end_bin < roi1->get_end_bin()) ext_end_bin = roi1->
get_end_bin();
2393 if (ext_end_bin < roi1->get_end_bin()) ext_end_bin = roi1->
get_end_bin();
2422 for (
int chid = 0; chid !=
nwire_w; chid ++){
2437 if (ext_end_bin < roi1->get_end_bin()) ext_end_bin = roi1->
get_end_bin();
2449 if (ext_end_bin < roi1->get_end_bin()) ext_end_bin = roi1->
get_end_bin();
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
void link(SignalROI *prev_roi, SignalROI *next_roi)
SignalROIChList rois_v_loose
ROI_refinement(Waveform::ChannelMaskMap &cmm, int nwire_u, int nwire_v, int nwire_w, float th_factor=3.0, float fake_signal_low_th=500, float fake_signal_high_th=1000, float fake_signal_low_th_ind_factor=1.0, float fake_signal_high_th_ind_factor=1.0, int pad=5, int break_roi_loop=2, float th_peak=3.0, float sep_peak=6.0, float low_peak_sep_threshold_pre=1200, int max_npeaks=200, float sigma=2, float th_percent=0.1)
std::vector< std::pair< int, int > > get_above_threshold(float th)
void set_ext_start_bin(int a)
std::list< SignalROI * > SignalROIList
void set_ext_end_bin(int a)
float fake_signal_low_th_ind_factor
SignalROIMap contained_rois
void unlink(SignalROI *prev_roi, SignalROI *next_roi)
double get_average_heights()
void CleanUpInductionROIs(int plane)
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
SignalROIChList rois_w_tight
SignalROIChList & get_v_rois()
Configuration find(Configuration &lst, const std::string &dotpath, const T &val)
Return dictionary in given list if it value at dotpath matches.
void BreakROI(SignalROI *roi, float rms)
SignalROIChList rois_v_tight
std::vector< float > & get_contents()
SignalROIChList rois_u_loose
float fake_signal_high_th
void ShrinkROIs(int plane, ROI_formation &roi_form)
void generate_merge_ROIs(int plane)
void load_data(int plane, const Array::array_xxf &r_data, ROI_formation &roi_form)
logptr_t logger(std::string name)
std::vector< SignalROIList > SignalROIChList
float low_peak_sep_threshold_pre
bool overlap(SignalROI *roi)
float fake_signal_high_th_ind_factor
void apply_roi(int plane, Array::array_xxf &r_data)
SignalROIChList rois_u_tight
std::map< int, std::vector< std::pair< int, int > > > bad_ch_map
void CleanUpCollectionROIs()
void CleanUpROIs(int plane)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
SignalROIChList & get_rois_by_plane(int plane)
SignalROIChList & get_u_rois()
int find_peak(Waveform::realseq_t &signal)
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
std::vector< SignalROI * > SignalROISelection
SignalROIChList & get_w_rois()
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
void BreakROI1(SignalROI *roi)
void refine_data(int plane, ROI_formation &roi_form)
QTextStream & endl(QTextStream &s)
Eigen::ArrayXXf array_xxf
A real, 2D array.
void refine_data_debug_mode(int plane, ROI_formation &roi_form, const std::string &cmd)
void CheckROIs(int plane, ROI_formation &roi_form)
void ShrinkROI(SignalROI *roi, ROI_formation &roi_form)
void BreakROIs(int plane, ROI_formation &roi_form)