From a21395bb51f84c6f75e405e553f5e39d517bc6b6 Mon Sep 17 00:00:00 2001 From: Wenqiang Gu Date: Wed, 14 Aug 2024 23:30:32 -0500 Subject: [PATCH 1/2] replace grouped filter with multigroup channel filters --- .../inc/WireCellSigProc/OmnibusNoiseFilter.h | 9 ++ sigproc/src/OmnibusNoiseFilter.cxx | 90 ++++++++++++------- 2 files changed, 68 insertions(+), 31 deletions(-) diff --git a/sigproc/inc/WireCellSigProc/OmnibusNoiseFilter.h b/sigproc/inc/WireCellSigProc/OmnibusNoiseFilter.h index 2ae3c4a6b..629f5e66e 100644 --- a/sigproc/inc/WireCellSigProc/OmnibusNoiseFilter.h +++ b/sigproc/inc/WireCellSigProc/OmnibusNoiseFilter.h @@ -65,6 +65,15 @@ namespace WireCell { std::map m_maskmap; size_t m_count{0}; + + // This little struct, named MGCF (Multi-Group Channel Filters), is used to associate a set of + // channels with a set of filters. See: https://github.com/WireCell/wire-cell-toolkit/issues/327 + struct MGCF { + std::vector channelgroups; + std::vector filters; + }; + + std::vector m_multigroup_chanfilters; }; } // namespace SigProc diff --git a/sigproc/src/OmnibusNoiseFilter.cxx b/sigproc/src/OmnibusNoiseFilter.cxx index ea62fbcbd..55c63b65f 100644 --- a/sigproc/src/OmnibusNoiseFilter.cxx +++ b/sigproc/src/OmnibusNoiseFilter.cxx @@ -59,16 +59,43 @@ void OmnibusNoiseFilter::configure(const WireCell::Configuration& cfg) jf.asString()); m_perchan_status.push_back(filt); } - for (auto jf : cfg["grouped_filters"]) { - auto filt = Factory::find_tn(jf.asString()); - log->debug("adding grouped filter: {} \"{}\"", m_grouped.size(), jf.asString()); - m_grouped.push_back(filt); - } auto jcndb = cfg["noisedb"]; m_noisedb = Factory::find_tn(jcndb.asString()); log->debug("using channel noise DB object: \"{}\"", jcndb.asString()); + // We should use multi-group channel filters, the interface below is maintained + // to ensure backwards compatibility. See: + // https://github.com/WireCell/wire-cell-toolkit/issues/327 + if ( !cfg["grouped_filters"].empty() ) { + MGCF mgcf; + mgcf.channelgroups = m_noisedb->coherent_channels(); + for (auto jf : cfg["grouped_filters"]) { + auto filt = Factory::find_tn(jf.asString()); + log->debug("adding grouped filter: {} \"{}\"", mgcf.filters.size(), jf.asString()); + mgcf.filters.push_back(filt); + } + m_multigroup_chanfilters.push_back(mgcf); + } + + for (auto jmgcf: cfg["multigroup_chanfilters"]) { + MGCF mgcf; + auto jgroups = jmgcf["channelgroups"]; + for (auto jgroup : jgroups) { + std::vector channel_group; + for (auto jch : jgroup) { + channel_group.push_back(jch.asInt()); + } + mgcf.channelgroups.push_back(channel_group); + } + for (auto jf: jmgcf["filters"]){ + auto filt = Factory::find_tn(jf.asString()); + log->debug("adding grouped filter: {} \"{}\"", mgcf.filters.size(), jf.asString()); + mgcf.filters.push_back(filt); + } + m_multigroup_chanfilters.push_back(mgcf); + } + m_intag = get(cfg, "intraces", m_intag); m_outtag = get(cfg, "outtraces", m_outtag); } @@ -182,38 +209,39 @@ bool OmnibusNoiseFilter::operator()(const input_pointer& inframe, output_pointer log->warn("warning, truncated or extended {} samples", nchanged_samples); } - int group_counter = 0; + // int group_counter = 0; int nunknownchans = 0; - for (auto group : m_noisedb->coherent_channels()) { - ++group_counter; - - int flag = 1; - - IChannelFilter::channel_signals_t chgrp; - for (auto ch : group) { // fix me: check if we don't actually have this channel - // std::cout << group_counter << " " << ch << " " << std::endl; - if (bychan.find(ch) == bychan.end()) { - ++nunknownchans; - flag = 0; - } - else { - chgrp[ch] = bychan[ch]->charge(); // copy... + for (const auto& mgcf : m_multigroup_chanfilters) { + for (auto group : mgcf.channelgroups) { + + int flag = 1; + + IChannelFilter::channel_signals_t chgrp; + for (auto ch : group) { // fix me: check if we don't actually have this channel + // std::cout << group_counter << " " << ch << " " << std::endl; + if (bychan.find(ch) == bychan.end()) { + ++nunknownchans; + flag = 0; + } + else { + chgrp[ch] = bychan[ch]->charge(); // copy... + } } - } + if (flag == 0) continue; - if (flag == 0) continue; + for (auto filter : mgcf.filters) { + auto masks = filter->apply(chgrp); + Waveform::merge(cmm, masks, m_maskmap); + } - for (auto filter : m_grouped) { - auto masks = filter->apply(chgrp); + for (auto cs : chgrp) { + // cs.second; // copy + bychan[cs.first]->charge().assign(cs.second.begin(), cs.second.end()); + } - Waveform::merge(cmm, masks, m_maskmap); - } + } // end of channel groups - for (auto cs : chgrp) { - // cs.second; // copy - bychan[cs.first]->charge().assign(cs.second.begin(), cs.second.end()); - } - } + } // end of MGCF if (nunknownchans) { log->debug("{} unknown channels (probably the channel selector is in use)", nunknownchans); From 58ac6b239018e90dfa542d5700193c916b7266ea Mon Sep 17 00:00:00 2001 From: Wenqiang Gu Date: Thu, 15 Aug 2024 11:32:08 -0500 Subject: [PATCH 2/2] add a warning for later reference, see issues 327 --- sigproc/src/OmnibusNoiseFilter.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/sigproc/src/OmnibusNoiseFilter.cxx b/sigproc/src/OmnibusNoiseFilter.cxx index 55c63b65f..0c5c5654e 100644 --- a/sigproc/src/OmnibusNoiseFilter.cxx +++ b/sigproc/src/OmnibusNoiseFilter.cxx @@ -63,6 +63,7 @@ void OmnibusNoiseFilter::configure(const WireCell::Configuration& cfg) auto jcndb = cfg["noisedb"]; m_noisedb = Factory::find_tn(jcndb.asString()); log->debug("using channel noise DB object: \"{}\"", jcndb.asString()); + log->warn("Use of CHND is deprecated and will be removed in the future."); // We should use multi-group channel filters, the interface below is maintained // to ensure backwards compatibility. See: