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);
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={}",
1672 int npeaks =
s.GetNPeaks();
1673 double *peak_pos =
s.GetPositionX();
1674 double *peak_height =
s.GetPositionY();
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);
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
SignalROIMap contained_rois
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
std::vector< float > & get_contents()
float low_peak_sep_threshold_pre
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.