15 #include <unordered_map> 22 using namespace WireCell::SigProc;
31 OmnibusNoiseFilter::~OmnibusNoiseFilter()
39 if (! cfg[
"nsamples"].isNull()) {
40 log->warn(
"OmnibusNoiseFilter: \"nsamples\" is an obsolete parameter, use \"nticks\"");
43 auto jmm = cfg[
"maskmap"];
44 for (
auto name : jmm.getMemberNames()) {
49 for (
auto jf : cfg[
"channel_filters"]) {
50 auto filt = Factory::find_tn<IChannelFilter>(jf.asString());
51 log->debug(
"OmnibusNoiseFilter: adding channel filter: {} \"{}\"",
55 for (
auto jf : cfg[
"channel_status_filters"]) {
56 auto filt = Factory::find_tn<IChannelFilter>(jf.asString());
57 log->debug(
"OmnibusNoiseFilter: adding channel status filter: {} \"{}\"",
61 for (
auto jf : cfg[
"grouped_filters"]) {
62 auto filt = Factory::find_tn<IChannelFilter>(jf.asString());
63 log->debug(
"OmnibusNoiseFilter: adding grouped filter: {} \"{}\"",
69 auto jcndb = cfg[
"noisedb"];
70 m_noisedb = Factory::find_tn<IChannelNoiseDatabase>(jcndb.asString());
71 log->debug(
"OmnibusNoiseFilter: using channel noise DB object: \"{}\"",
82 cfg[
"maskmap"][
"chirp"] =
"bad";
83 cfg[
"maskmap"][
"noisy"] =
"bad";
85 cfg[
"channel_filters"][0] =
"mbOneChannelNoise";
86 cfg[
"channel_status_filters"][0] =
"mbOneChannelStatus";
87 cfg[
"grouped_filters"][0] =
"mbCoherentNoiseSub";
108 if (traces.empty()) {
109 log->warn(
"OmnibusNoiseFilter: no traces for tag \"{}\", sending empty frame",
m_intag);
110 outframe = std::make_shared<SimpleFrame>(inframe->ident(), inframe->time(),
111 std::make_shared<ITrace::vector>(),
118 log->debug(
"OmnibusNoiseFilter: will resize working waveforms from {} to {}",
119 traces.at(0)->charge().size(),
m_nticks);
124 m_nticks = traces.at(0)->charge().size();
125 log->debug(
"OmnibusNoiseFilter: nticks based on first waveform: {}",
m_nticks);
134 std::vector<int> bad_channels =
m_noisedb->bad_channels();
140 for (
size_t i = 0; i< bad_channels.size();i++){
141 temp[bad_channels.at(i)].push_back(bad_bins);
145 temp_map[
"bad"] = temp;
150 int nchanged_samples = 0;
153 std::unordered_map<int, SimpleTrace*> bychan;
154 for (
auto trace : traces) {
155 int ch =
trace->channel();
162 if (
find(bad_channels.begin(), bad_channels.end(),ch) == bad_channels.end()) {
164 auto const& charge =
trace->charge();
165 const size_t ncharges = charge.size();
188 if (nchanged_samples) {
189 log->warn(
"OmnibusNoiseFilter: warning, truncated or extended {} samples", nchanged_samples);
192 int group_counter = 0;
194 for (
auto group :
m_noisedb->coherent_channels()) {
200 for (
auto ch : group) {
202 if (bychan.find(ch)==bychan.end()) {
207 chgrp[ch] = bychan[ch]->charge();
211 if (flag == 0)
continue;
214 auto masks =
filter->apply(chgrp);
219 for (
auto cs : chgrp) {
221 bychan[
cs.first]->charge().assign(
cs.second.begin(),
cs.second.end());
226 log->debug(
"OmnibusNoiseFilter: {} unknown channels (probably the channel selector is in use)", nunknownchans);
230 for (
auto& it : bychan) {
231 const int ch = it.first;
234 auto masks =
filter->apply(ch, signal);
241 for (
auto&
cs : bychan) {
247 auto sframe =
new SimpleFrame(inframe->ident(), inframe->time(), itraces, inframe->tick(), cmm);
249 for (
size_t ind=0; ind<itraces.size(); ++ind) {
253 sframe->tag_frame(
"noisefilter");
std::shared_ptr< const ITrace > pointer
std::vector< WireCell::IChannelFilter::pointer > m_perchan
virtual void configure(const WireCell::Configuration &config)
IConfigurable interface.
Waveform::realseq_t signal_t
std::map< std::string, std::string > m_maskmap
std::vector< pointer > vector
virtual bool operator()(const input_pointer &in, output_pointer &out)
IFrameFilter interface.
std::vector< WireCell::IChannelFilter::pointer > m_grouped
std::shared_ptr< const IFrame > input_pointer
virtual WireCell::Configuration default_configuration() const
Optional, override to return a hard-coded default configuration.
Configuration find(Configuration &lst, const std::string &dotpath, const T &val)
Return dictionary in given list if it value at dotpath matches.
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
std::shared_ptr< const IFrame > output_pointer
logptr_t logger(std::string name)
void log(source_loc source, level::level_enum lvl, const char *fmt, const Args &...args)
std::vector< WireCell::IChannelFilter::pointer > m_perchan_status
std::map< int, signal_t > channel_signals_t
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
ChargeSequence & charge()
WireCell::ITrace::vector tagged_traces(WireCell::IFrame::pointer frame, WireCell::IFrame::tag_t tag)
Json::Value Configuration
WireCell::IChannelNoiseDatabase::pointer m_noisedb
WIRECELL_FACTORY(OmnibusNoiseFilter, WireCell::SigProc::OmnibusNoiseFilter, WireCell::IFrameFilter, WireCell::IConfigurable) using namespace WireCell
std::vector< size_t > trace_list_t