Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
WireCell::SigProc::OmniChannelNoiseDB Class Reference

#include <OmniChannelNoiseDB.h>

Inheritance diagram for WireCell::SigProc::OmniChannelNoiseDB:
WireCell::IChannelNoiseDatabase WireCell::IConfigurable WireCell::IComponent< IChannelNoiseDatabase > WireCell::IComponent< IConfigurable > WireCell::Interface WireCell::Interface wcls::ChannelNoiseDB wcls::ChannelSelectorDB

Classes

struct  ChannelInfo
 

Public Member Functions

 OmniChannelNoiseDB ()
 
virtual ~OmniChannelNoiseDB ()
 
virtual void configure (const WireCell::Configuration &config)
 Accept a configuration. More...
 
virtual WireCell::Configuration default_configuration () const
 Optional, override to return a hard-coded default configuration. More...
 
virtual double sample_time () const
 FIXME: how to handle state changes? More...
 
virtual double nominal_baseline (int channel) const
 Return a nominal baseline correction (additive offset) More...
 
virtual double gain_correction (int channel) const
 
virtual double response_offset (int channel) const
 Return a time offset associated with the response(). More...
 
virtual double min_rms_cut (int channel) const
 
virtual double max_rms_cut (int channel) const
 
virtual int pad_window_front (int channel) const
 
virtual int pad_window_back (int channel) const
 
virtual float coherent_nf_decon_limit (int channel) const
 
virtual float coherent_nf_decon_lf_cutoff (int channel) const
 
virtual float coherent_nf_decon_limit1 (int channel) const
 
virtual float coherent_nf_adc_limit (int channel) const
 
virtual float coherent_nf_protection_factor (int channel) const
 
virtual float coherent_nf_min_adc_limit (int channel) const
 
virtual float coherent_nf_roi_min_max_ratio (int channel) const
 
virtual const filter_trcrc (int channel) const
 Return the filter for the RC+RC coupling response function. More...
 
virtual const filter_tconfig (int channel) const
 Return the filter to correct any wrongly configured channels. More...
 
virtual const filter_tnoise (int channel) const
 Return the filter to attenuate noise. More...
 
virtual const filter_tresponse (int channel) const
 A nominal detector response spectrum for a given channel. More...
 
virtual std::vector< channel_group_tcoherent_channels () const
 Return channel grouping for coherent noise subtraction. More...
 
virtual channel_group_t bad_channels () const
 Return channels which are considered a'priori "bad". More...
 
virtual channel_group_t miscfg_channels () const
 Return channels which are considered a'priori "misconfigured". More...
 
- Public Member Functions inherited from WireCell::IChannelNoiseDatabase
virtual ~IChannelNoiseDatabase ()
 
- Public Member Functions inherited from WireCell::IComponent< IChannelNoiseDatabase >
virtual ~IComponent ()
 
- Public Member Functions inherited from WireCell::Interface
virtual ~Interface ()
 
- Public Member Functions inherited from WireCell::IConfigurable
virtual ~IConfigurable ()
 
- Public Member Functions inherited from WireCell::IComponent< IConfigurable >
virtual ~IComponent ()
 

Protected Member Functions

virtual void set_bad_channels (const channel_group_t &bad)
 
virtual void set_misconfigured (const std::vector< int > &channels, double from_gain, double from_shaping, double to_gain, double to_shaping, bool reset=false)
 

Private Types

typedef std::shared_ptr< filter_tshared_filter_t
 
typedef std::vector< shared_filter_tfilter_vector_t
 

Private Member Functions

const ChannelInfodbget (int ch) const
 
std::vector< int > parse_channels (const Json::Value &jchannels)
 
shared_filter_t make_filter (std::complex< float > defval=std::complex< float >(1, 0))
 
shared_filter_t default_filter ()
 
shared_filter_t parse_freqmasks (Json::Value jfm)
 
shared_filter_t parse_rcrc (Json::Value jrcrc, int nrc)
 
double parse_gain (Json::Value jreconfig)
 
shared_filter_t parse_reconfig (Json::Value jreconfig)
 
shared_filter_t get_reconfig (double from_gain, double from_shaping, double to_gain, double to_shaping)
 
shared_filter_t parse_response (Json::Value jreconfig)
 
void update_channels (Json::Value cfg)
 
ChannelInfoget_ci (int chid)
 

Private Attributes

double m_tick
 
int m_nsamples
 
IAnodePlane::pointer m_anode
 
IFieldResponse::pointer m_fr
 
int m_rc_layers
 
std::unordered_map< int, ChannelInfom_db
 
std::vector< channel_group_tm_channel_groups
 
channel_group_t m_bad_channels
 
channel_group_t m_miscfg_channels
 
std::unordered_map< int, shared_filter_tm_rcrc_cache
 
std::unordered_map< int, shared_filter_tm_reconfig_cache
 
std::unordered_map< int, shared_filter_tm_waveform_cache
 
std::unordered_map< int, shared_filter_tm_response_cache
 
Log::logptr_t log
 

Additional Inherited Members

- Public Types inherited from WireCell::IChannelNoiseDatabase
typedef WireCell::Waveform::compseq_t filter_t
 The data type for all frequency-space, multiplicative filters. More...
 
typedef std::vector< int > channel_group_t
 
- Public Types inherited from WireCell::IComponent< IChannelNoiseDatabase >
typedef std::shared_ptr< IChannelNoiseDatabasepointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 
- Public Types inherited from WireCell::Interface
typedef std::shared_ptr< Interfacepointer
 
- Public Types inherited from WireCell::IComponent< IConfigurable >
typedef std::shared_ptr< IConfigurablepointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 

Detailed Description

Definition at line 24 of file OmniChannelNoiseDB.h.

Member Typedef Documentation

Definition at line 108 of file OmniChannelNoiseDB.h.

Definition at line 107 of file OmniChannelNoiseDB.h.

Constructor & Destructor Documentation

OmniChannelNoiseDB::OmniChannelNoiseDB ( )

Create a configurable channel noise DB for digitized waveforms with the given size and number of samples. Default is for microphone.

Definition at line 14 of file OmniChannelNoiseDB.cxx.

OmniChannelNoiseDB::~OmniChannelNoiseDB ( )
virtual

Definition at line 21 of file OmniChannelNoiseDB.cxx.

22 {
23  // for (auto it = m_db.begin(); it!= m_db.end(); it++){
24  // delete it->second;
25  // }
26  // m_db.clear();
27 }

Member Function Documentation

virtual channel_group_t WireCell::SigProc::OmniChannelNoiseDB::bad_channels ( ) const
inlinevirtual

Return channels which are considered a'priori "bad".

Reimplemented from WireCell::IChannelNoiseDatabase.

Reimplemented in wcls::ChannelSelectorDB.

Definition at line 68 of file OmniChannelNoiseDB.h.

68  {
69  return m_bad_channels;
70  }
virtual std::vector<channel_group_t> WireCell::SigProc::OmniChannelNoiseDB::coherent_channels ( ) const
inlinevirtual

Return channel grouping for coherent noise subtraction.

Implements WireCell::IChannelNoiseDatabase.

Definition at line 65 of file OmniChannelNoiseDB.h.

65  {
66  return m_channel_groups;
67  }
std::vector< channel_group_t > m_channel_groups
float OmniChannelNoiseDB::coherent_nf_adc_limit ( int  channel) const
virtual
float OmniChannelNoiseDB::coherent_nf_decon_lf_cutoff ( int  channel) const
virtual
float OmniChannelNoiseDB::coherent_nf_decon_limit ( int  channel) const
virtual
float OmniChannelNoiseDB::coherent_nf_decon_limit1 ( int  channel) const
virtual
float OmniChannelNoiseDB::coherent_nf_min_adc_limit ( int  channel) const
virtual
float OmniChannelNoiseDB::coherent_nf_protection_factor ( int  channel) const
virtual
float OmniChannelNoiseDB::coherent_nf_roi_min_max_ratio ( int  channel) const
virtual
const IChannelNoiseDatabase::filter_t & OmniChannelNoiseDB::config ( int  channel) const
virtual

Return the filter to correct any wrongly configured channels.

Implements WireCell::IChannelNoiseDatabase.

Definition at line 731 of file OmniChannelNoiseDB.cxx.

732 {
733  auto filt = dbget(channel).config;
734  if (filt) {
735  return *filt;
736  }
737  static filter_t dummy;
738  return dummy;
739 }
const ChannelInfo & dbget(int ch) const
WireCell::Waveform::compseq_t filter_t
The data type for all frequency-space, multiplicative filters.
cet::LibraryManager dummy("noplugin")
void OmniChannelNoiseDB::configure ( const WireCell::Configuration config)
virtual

Accept a configuration.

Implements WireCell::IConfigurable.

Reimplemented in wcls::ChannelNoiseDB, and wcls::ChannelSelectorDB.

Definition at line 590 of file OmniChannelNoiseDB.cxx.

591 {
592  m_tick = get(cfg, "tick", m_tick);
593  m_nsamples = get(cfg, "nsamples", m_nsamples);
594  std::string anode_tn = get<std::string>(cfg, "anode", "AnodePlane");
595  m_anode = Factory::find_tn<IAnodePlane>(anode_tn);
596  std::string fr_tn = get<std::string>(cfg, "field_response", "FieldResponse");
597  m_fr = Factory::find_tn<IFieldResponse>(fr_tn);
598 
599  // WARNING: this assumes channel numbers count from 0 with no gaps!
600  //int nchans = m_anode->channels().size();
601  //std::cerr << "noise database with " << nchans << " channels\n";
602  //m_db.resize(nchans);
603 
604  // clear any previous config, and recover the memory
605  // for (auto it = m_db.begin(); it!= m_db.end(); it++){
606  // delete it->second;
607  // }
608  // m_db.clear();
609  for(auto ch: m_anode->channels()){
610  // m_db.insert(std::make_pair(ch, new ChannelInfo));
611  m_db[ch] = ChannelInfo();
612  }
613 
614  m_channel_groups.clear();
615  auto jgroups = cfg["groups"];
616  for (auto jgroup: jgroups) {
617  std::vector<int> channel_group;
618  for (auto jch: jgroup) {
619  channel_group.push_back(jch.asInt());
620  }
621  m_channel_groups.push_back(channel_group);
622  }
623  m_bad_channels.clear();
624  for (auto jch : cfg["bad"]) {
625  m_bad_channels.push_back(jch.asInt());
626  }
627  std::sort(m_bad_channels.begin(), m_bad_channels.end());
628  if (m_bad_channels.size()) {
629  log->debug("OmniChannelNoiseDB: setting {}:[{},{}] bad channels",
630  m_bad_channels.size(), m_bad_channels.front(), m_bad_channels.back());
631  }
632 
633 
634  m_miscfg_channels.clear();
635  for (auto jci : cfg["channel_info"]) {
636  update_channels(jci);
637  }
638 }
std::string string
Definition: nybbler.cc:12
cfg
Definition: dbjson.py:29
std::unordered_map< int, ChannelInfo > m_db
std::vector< channel_group_t > m_channel_groups
const ChannelInfo& WireCell::SigProc::OmniChannelNoiseDB::dbget ( int  ch) const
inlineprivate

Definition at line 138 of file OmniChannelNoiseDB.h.

138  {
139  auto it = m_db.find(ch);
140  if (it == m_db.end()) {
141  //it = m_db.find(defch);
142  //return *(it->second);
143  // m_db.insert(std::make_pair(ch, new ChannelInfo));
144  // return *(m_db[ch]);
145  THROW(KeyError() << errmsg{String::format("no db info for channel %d", ch)});
146  }
147  return it->second;
148  //return m_db.at(ch);
149  }
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
#define THROW(e)
Definition: Exceptions.h:25
std::unordered_map< int, ChannelInfo > m_db
std::string format(const std::string &form, TYPES...objs)
Definition: String.h:45
WireCell::Configuration OmniChannelNoiseDB::default_configuration ( ) const
virtual

Optional, override to return a hard-coded default configuration.

These must be provided

Reimplemented from WireCell::IConfigurable.

Definition at line 55 of file OmniChannelNoiseDB.cxx.

56 {
58  // The assumed time-domain sample period used to make response spetra.
59  cfg["tick"] = m_tick;
60  // The number of *frequency domain* sample. This is NOT anything
61  // related to the length of a waveform to which this class may be
62  // applied, except by accident or contrivance.
63  cfg["nsamples"] = m_nsamples;
64  cfg["anode"] = "AnodePlane";
65  cfg["field_response"] = "FieldResponse";
66 
67  /// These must be provided
68  cfg["groups"] = Json::arrayValue;
69  cfg["channel_info"] = Json::arrayValue;
70 
71  return cfg;
72 }
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
OmniChannelNoiseDB::shared_filter_t OmniChannelNoiseDB::default_filter ( )
private

Definition at line 148 of file OmniChannelNoiseDB.cxx.

149 {
150  static shared_filter_t def = make_filter();
151  return def;
152 }
std::shared_ptr< filter_t > shared_filter_t
shared_filter_t make_filter(std::complex< float > defval=std::complex< float >(1, 0))
double OmniChannelNoiseDB::gain_correction ( int  channel) const
virtual

Return simple gain correction (a multiplicative, unitless scaling) to apply to a given channel.

Implements WireCell::IChannelNoiseDatabase.

Definition at line 656 of file OmniChannelNoiseDB.cxx.

OmniChannelNoiseDB::ChannelInfo & OmniChannelNoiseDB::get_ci ( int  chid)
private

Definition at line 369 of file OmniChannelNoiseDB.cxx.

370 {
371  auto it = m_db.find(chid);
372  if (it == m_db.end()) {
373  THROW(KeyError() << errmsg{String::format("no db info for channel %d", chid)});
374  }
375  return it->second;
376  //return m_db.at(chid);
377 }
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
#define THROW(e)
Definition: Exceptions.h:25
std::unordered_map< int, ChannelInfo > m_db
std::string format(const std::string &form, TYPES...objs)
Definition: String.h:45
OmniChannelNoiseDB::shared_filter_t OmniChannelNoiseDB::get_reconfig ( double  from_gain,
double  from_shaping,
double  to_gain,
double  to_shaping 
)
private

Definition at line 239 of file OmniChannelNoiseDB.cxx.

241 {
242  // kind of evil.
243  int key = int(round(10.0*from_gain/(units::mV/units::fC))) << 24
244  | int(round(10.0*from_shaping/units::us)) << 16
245  | int(round(10.0*to_gain/(units::mV/units::fC))) << 8
246  | int(round(10.0*to_shaping/units::us));
247 
248  // std::cerr << "KEY:" << key
249  // << " fg="<<from_gain/(units::mV/units::fC) << " mV/fC,"
250  // << " fs=" << from_shaping/units::us << " us,"
251  // << " tg="<<to_gain/(units::mV/units::fC) << " mV/fC,"
252  // << " ts="<<to_shaping/units::us << " us,"
253  // << " m_tick=" << m_tick/units::us << " us."
254  // << std::endl;
255 
256 
257  auto it = m_reconfig_cache.find(key);
258  if (it != m_reconfig_cache.end()) {
259  return it->second;
260  }
261 
262  Response::ColdElec from_ce(from_gain, from_shaping);
263  Response::ColdElec to_ce(to_gain, to_shaping);
264  // auto to_sig = to_ce.generate(WireCell::Binning(m_nsamples, 0, m_nsamples*m_tick));
265  // auto from_sig = from_ce.generate(WireCell::Binning(m_nsamples, 0, m_nsamples*m_tick));
266  auto to_sig = to_ce.generate(WireCell::Waveform::Domain(0, m_nsamples*m_tick), m_nsamples);
267  auto from_sig = from_ce.generate(WireCell::Waveform::Domain(0, m_nsamples*m_tick), m_nsamples);
268 
269  auto to_filt = Waveform::dft(to_sig);
270  auto from_filt = Waveform::dft(from_sig);
271 
272  //auto from_filt_sum = Waveform::sum(from_filt);
273  //auto to_filt_sum = Waveform::sum(to_filt);
274 
275  Waveform::shrink(to_filt, from_filt); // divide
276  auto filt = std::make_shared<filter_t>(to_filt);
277 
278  // std::cerr << filt->at(0) << " " << filt->at(1) << std::endl;
279 
280  // std::cerr << "OmniChannelNoiseDB: "
281  // << " from_sig sum=" << Waveform::sum(from_sig)
282  // << " to_sig sum=" << Waveform::sum(to_sig)
283  // << " from_filt sum=" << from_filt_sum
284  // << " to_filt sum=" << to_filt_sum
285  // << " rat_filt sum=" << Waveform::sum(to_filt)
286  // << std::endl;
287 
288 
290  return filt;
291 }
static const double mV
Definition: Units.h:180
compseq_t dft(realseq_t seq)
Definition: Waveform.cxx:141
std::pair< double, double > Domain
Definition: Waveform.h:75
void shrink(Sequence< Val > &seq, const Sequence< Val > &other)
Shrink (divide) seq values by values from the other sequence.
Definition: Waveform.h:162
def key(type, name=None)
Definition: graph.py:13
static const double fC
Definition: Units.h:113
std::unordered_map< int, shared_filter_t > m_reconfig_cache
static const double us
Definition: Units.h:105
OmniChannelNoiseDB::shared_filter_t OmniChannelNoiseDB::make_filter ( std::complex< float >  defval = std::complex<float>(1,0))
private

Definition at line 144 of file OmniChannelNoiseDB.cxx.

145 {
146  return std::make_shared<filter_t>(m_nsamples, defval);
147 }
double OmniChannelNoiseDB::max_rms_cut ( int  channel) const
virtual
double OmniChannelNoiseDB::min_rms_cut ( int  channel) const
virtual
virtual channel_group_t WireCell::SigProc::OmniChannelNoiseDB::miscfg_channels ( ) const
inlinevirtual

Return channels which are considered a'priori "misconfigured".

Reimplemented from WireCell::IChannelNoiseDatabase.

Reimplemented in wcls::ChannelSelectorDB.

Definition at line 71 of file OmniChannelNoiseDB.h.

71  {
72  return m_miscfg_channels;
73  }
const IChannelNoiseDatabase::filter_t & OmniChannelNoiseDB::noise ( int  channel) const
virtual

Return the filter to attenuate noise.

Implements WireCell::IChannelNoiseDatabase.

Definition at line 741 of file OmniChannelNoiseDB.cxx.

742 {
743  auto filt = dbget(channel).noise;
744  if (filt) {
745  return *filt;
746  }
747  static filter_t dummy;
748  return dummy;
749 }
const ChannelInfo & dbget(int ch) const
WireCell::Waveform::compseq_t filter_t
The data type for all frequency-space, multiplicative filters.
cet::LibraryManager dummy("noplugin")
double OmniChannelNoiseDB::nominal_baseline ( int  channel) const
virtual

Return a nominal baseline correction (additive offset)

Implements WireCell::IChannelNoiseDatabase.

Definition at line 651 of file OmniChannelNoiseDB.cxx.

int OmniChannelNoiseDB::pad_window_back ( int  channel) const
virtual
int OmniChannelNoiseDB::pad_window_front ( int  channel) const
virtual
std::vector< int > OmniChannelNoiseDB::parse_channels ( const Json::Value jchannels)
private

Definition at line 96 of file OmniChannelNoiseDB.cxx.

97 {
98  std::vector<int> ret;
99 
100  // single channel
101  if (jchannels.isInt()) {
102  ret.push_back(jchannels.asInt());
103  return ret;
104  }
105 
106  // array of explicit channels
107  if (jchannels.isArray()) {
108  const int nch = jchannels.size();
109  ret.resize(nch);
110  for (int ind=0; ind<nch; ++ind) {
111  ret[ind] = jchannels[ind].asInt();
112  }
113  return ret;
114  }
115 
116  // else, assume an object
117 
118  // range
119  if (jchannels.isMember("first") && jchannels.isMember("last")) {
120  const int chf = jchannels["first"].asInt();
121  const int chl = jchannels["last"].asInt();
122  const int nch = chl-chf+1;
123  ret.resize(nch);
124  for (int ind=0; ind < nch; ++ind) {
125  ret[ind] = chf + ind;
126  }
127  return ret;
128  }
129 
130  // wire plane id
131  if (jchannels.isMember("wpid")) {
132  WirePlaneId wpid(jchannels["wpid"].asInt());
133  for (auto ch : m_anode->channels()) {
134  if (m_anode->resolve(ch) == wpid) {
135  ret.push_back(ch);
136  }
137  }
138  return ret;
139  }
140 
141  return ret;
142 }
OmniChannelNoiseDB::shared_filter_t OmniChannelNoiseDB::parse_freqmasks ( Json::Value  jfm)
private

Definition at line 154 of file OmniChannelNoiseDB.cxx.

155 {
156  if (jfm.isNull()) {
157  return default_filter();
158  }
159 
160  auto spectrum = make_filter(std::complex<float>(1,0));
161  for (auto jone : jfm) {
162  double value = jone["value"].asDouble();
163  int lo = std::max(jone["lobin"].asInt(), 0);
164  int hi = std::min(jone["hibin"].asInt(), m_nsamples-1);
165  // std::cerr << "freqmasks: set [" << lo << "," << hi << "] to " << value << std::endl;
166  for (int ind=lo; ind <= hi; ++ind) { // inclusive
167  spectrum->at(ind) = value;
168  }
169  }
170  return spectrum;
171 }
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
shared_filter_t make_filter(std::complex< float > defval=std::complex< float >(1, 0))
double OmniChannelNoiseDB::parse_gain ( Json::Value  jreconfig)
private

Definition at line 214 of file OmniChannelNoiseDB.cxx.

215 {
216  if (jreconfig.empty()) {
217  return 1.0;
218  }
219 
220  const double from_gain = jreconfig["from"]["gain"].asDouble();
221  const double to_gain = jreconfig["to"]["gain"].asDouble();
222  return to_gain/from_gain;
223 }
OmniChannelNoiseDB::shared_filter_t OmniChannelNoiseDB::parse_rcrc ( Json::Value  jrcrc,
int  nrc 
)
private

Definition at line 173 of file OmniChannelNoiseDB.cxx.

174 {
175  if (jrcrc.isNull()) {
176  return default_filter();
177  }
178  const double rcrc_val = jrcrc.asDouble();
179  const int key = int(round(1000*rcrc_val/units::ms));
180  auto it = m_rcrc_cache.find(key);
181  if (it != m_rcrc_cache.end()) {
182  return it->second;
183  }
184 
185  Response::SimpleRC rcres(rcrc_val, m_tick);
186  // auto signal = rcres.generate(WireCell::Binning(m_nsamples, 0, m_nsamples*m_tick));
187  auto signal = rcres.generate(WireCell::Waveform::Domain(0, m_nsamples*m_tick), m_nsamples);
188 
189  Waveform::compseq_t spectrum = Waveform::dft(signal);
190  // get the square of it because there are two RC filters
191  Waveform::compseq_t spectrum2 = spectrum;
192  // Waveform::scale(spectrum2,spectrum);
193 
194  // std::cerr << "[wgu] parse_rcrc nrc= " << nrc << std::endl;
195  nrc --;
196  while(nrc>0){
197  // std::cerr << "[wgu] more nrc= " << nrc << std::endl;
198  Waveform::scale(spectrum2,spectrum);
199  nrc --;
200  }
201 
202 
203  // std::cerr << "OmniChannelNoiseDB:: get rcrc as: " << rcrc_val
204  // << " sum=" << Waveform::sum(spectrum2)
205  // << std::endl;
206 
207  auto ret = std::make_shared<filter_t>(spectrum2);
208  m_rcrc_cache[key] = ret;
209  return ret;
210 }
std::unordered_map< int, shared_filter_t > m_rcrc_cache
static const double ms
Definition: Units.h:104
compseq_t dft(realseq_t seq)
Definition: Waveform.cxx:141
std::pair< double, double > Domain
Definition: Waveform.h:75
def key(type, name=None)
Definition: graph.py:13
void scale(Sequence< Val > &seq, Val scalar)
Scale (multiply) sequence values by scalar.
Definition: Waveform.h:146
Sequence< complex_t > compseq_t
A complex-valued sequence, eg for discrete spectrum powers.
Definition: Waveform.h:34
OmniChannelNoiseDB::shared_filter_t OmniChannelNoiseDB::parse_reconfig ( Json::Value  jreconfig)
private

Definition at line 225 of file OmniChannelNoiseDB.cxx.

226 {
227  if (jreconfig.empty()) {
228  return default_filter();
229  }
230 
231  const double from_gain = jreconfig["from"]["gain"].asDouble();
232  const double from_shaping = jreconfig["from"]["shaping"].asDouble();
233  const double to_gain = jreconfig["to"]["gain"].asDouble();
234  const double to_shaping = jreconfig["to"]["shaping"].asDouble();
235 
236 
237  return get_reconfig(from_gain, from_shaping, to_gain, to_shaping);
238 }
shared_filter_t get_reconfig(double from_gain, double from_shaping, double to_gain, double to_shaping)
OmniChannelNoiseDB::shared_filter_t OmniChannelNoiseDB::parse_response ( Json::Value  jreconfig)
private

Definition at line 313 of file OmniChannelNoiseDB.cxx.

314 {
315  if (jfilt.isMember("wpid")) {
316  WirePlaneId wpid(jfilt["wpid"].asInt());
317  auto it = m_response_cache.find(wpid.ident());
318  if (it != m_response_cache.end()) {
319  return it->second;
320  }
321  auto const& fr = m_fr->field_response();
322  auto fravg = Response::wire_region_average(fr);
323  auto const& pr = fravg.planes[wpid.index()];
324 
325  // full length waveform
326  std::vector<float> waveform(m_nsamples, 0.0);
327  for (auto const& path : pr.paths) {
328  auto const& current = path.current;
329  const size_t nsamp = std::min(m_nsamples, (int)current.size());
330  for (size_t ind=0; ind<nsamp; ++ind) {
331  waveform[ind] += current[ind];
332  }
333  }
334  auto spectrum = WireCell::Waveform::dft(waveform);
335  auto ret = std::make_shared<filter_t>(spectrum);
336  m_response_cache[wpid.ident()] = ret;
337  return ret;
338  }
339 
340  if (jfilt.isMember("waveform") && jfilt.isMember("waveformid")) {
341  int id = jfilt["waveformid"].asInt();
342  auto it = m_waveform_cache.find(id);
343  if (it != m_waveform_cache.end()) {
344  return it->second;
345  }
346 
347  auto jwave = jfilt["waveform"];
348  const int nsamp = std::min(m_nsamples, (int)jwave.size());
349 
350  // Explicitly given waveform
351  std::vector<float> waveform(m_nsamples, 0.0);
352  for (int ind=0; ind<nsamp; ++ind) {
353  waveform[ind] = jwave[ind].asFloat();
354  }
355 
356  auto spectrum = WireCell::Waveform::dft(waveform);
357  auto ret = std::make_shared<filter_t>(spectrum);
358  m_waveform_cache[id] = ret;
359  return ret;
360  }
361 
362  // this default return is special in that it's empty instead of
363  // being a flat, unity spectrum.
364  static shared_filter_t empty = std::make_shared<filter_t>();
365  return empty;
366 }
std::unordered_map< int, shared_filter_t > m_response_cache
Schema::FieldResponse wire_region_average(const Schema::FieldResponse &fr)
Definition: Response.cxx:99
std::unordered_map< int, shared_filter_t > m_waveform_cache
compseq_t dft(realseq_t seq)
Definition: Waveform.cxx:141
static Entry * current
std::shared_ptr< filter_t > shared_filter_t
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:92
const IChannelNoiseDatabase::filter_t & OmniChannelNoiseDB::rcrc ( int  channel) const
virtual

Return the filter for the RC+RC coupling response function.

Implements WireCell::IChannelNoiseDatabase.

Definition at line 721 of file OmniChannelNoiseDB.cxx.

722 {
723  auto filt = dbget(channel).rcrc;
724  if (filt) {
725  return *filt;
726  }
727  static filter_t dummy;
728  return dummy;
729 }
const ChannelInfo & dbget(int ch) const
WireCell::Waveform::compseq_t filter_t
The data type for all frequency-space, multiplicative filters.
cet::LibraryManager dummy("noplugin")
const IChannelNoiseDatabase::filter_t & OmniChannelNoiseDB::response ( int  channel) const
virtual

A nominal detector response spectrum for a given channel.

Implements WireCell::IChannelNoiseDatabase.

Definition at line 751 of file OmniChannelNoiseDB.cxx.

752 {
753  auto filt = dbget(channel).response;
754  if (filt) {
755  return *filt;
756  }
757  static filter_t dummy;
758  return dummy;
759 }
const ChannelInfo & dbget(int ch) const
WireCell::Waveform::compseq_t filter_t
The data type for all frequency-space, multiplicative filters.
cet::LibraryManager dummy("noplugin")
double OmniChannelNoiseDB::response_offset ( int  channel) const
virtual

Return a time offset associated with the response().

Implements WireCell::IChannelNoiseDatabase.

Definition at line 661 of file OmniChannelNoiseDB.cxx.

double OmniChannelNoiseDB::sample_time ( ) const
virtual

FIXME: how to handle state changes?

Return the time-domain sample period (time in system of units) which is was used in producing the filter response spectral functions (filter_t).

Warning: take care that the number of frequency samples (filter_t::size()) is fixed and may not match the number of ticks in your waveform.

Implements WireCell::IChannelNoiseDatabase.

Definition at line 644 of file OmniChannelNoiseDB.cxx.

645 {
646  return m_tick;
647 }
virtual void WireCell::SigProc::OmniChannelNoiseDB::set_bad_channels ( const channel_group_t bad)
inlineprotectedvirtual

Definition at line 85 of file OmniChannelNoiseDB.h.

85  {
86  m_bad_channels = bad;
87  }
void OmniChannelNoiseDB::set_misconfigured ( const std::vector< int > &  channels,
double  from_gain,
double  from_shaping,
double  to_gain,
double  to_shaping,
bool  reset = false 
)
protectedvirtual

Definition at line 292 of file OmniChannelNoiseDB.cxx.

296 {
297  if (reset) {
298  auto def = default_filter();
299  for (auto& it : m_db) {
300  it.second.config = def;
301  }
302  }
303  auto val = get_reconfig(from_gain, from_shaping, to_gain, to_shaping);
304  for (int ch : channels) {
305  //m_db.at(ch).config = val;
306  //dbget(ch).config = val;
307  get_ci(ch).config = val;
308  m_miscfg_channels.push_back(ch);
309  }
310 }
shared_filter_t get_reconfig(double from_gain, double from_shaping, double to_gain, double to_shaping)
QTextStream & reset(QTextStream &s)
std::unordered_map< int, ChannelInfo > m_db
void OmniChannelNoiseDB::update_channels ( Json::Value  cfg)
private

Definition at line 386 of file OmniChannelNoiseDB.cxx.

387 {
388  auto chans = parse_channels(cfg["channels"]);
389 
390  if (cfg.isMember("nominal_baseline")) {
391  double val = cfg["nominal_baseline"].asDouble();
392  dump_cfg("baseline", chans, val);
393  for (int ch : chans) {
394  //m_db.at(ch).nominal_baseline = val;
395  //dbget(ch).nominal_baseline = val;
397  }
398  }
399  if (cfg.isMember("gain_correction")) {
400  double val = cfg["gain_correction"].asDouble();
401  dump_cfg("gain", chans, val);
402  for (int ch : chans) {
403  //m_db.at(ch).gain_correction = val;
404  //dbget(ch).gain_correction = val;
405  get_ci(ch).gain_correction = val;
406  }
407  }
408  // fixme: why have two ways to set the same thing?
409  {
410  auto jfilt = cfg["reconfig"];
411  if (!jfilt.isNull()) {
412  auto val = parse_gain(jfilt);
413  dump_cfg("gain", chans, val);
414  for (int ch : chans) {
415  //m_db.at(ch).gain_correction = val;
416  //dbget(ch).gain_correction = val;
417  get_ci(ch).gain_correction = val;
418  }
419  }
420  }
421 
422  if (cfg.isMember("response_offset")) {
423  double val = cfg["response_offset"].asDouble();
424  dump_cfg("offset", chans, val);
425  for (int ch : chans) {
426  //m_db.at(ch).response_offset = val;
427  //dbget(ch).response_offset = val;
428  get_ci(ch).response_offset = val;
429  }
430  }
431  if (cfg.isMember("min_rms_cut")) {
432  double val = cfg["min_rms_cut"].asDouble();
433  dump_cfg("minrms", chans, val);
434  for (int ch : chans) {
435  //m_db.at(ch).min_rms_cut = val;
436  //dbget(ch).min_rms_cut = val;
437  get_ci(ch).min_rms_cut = val;
438  }
439  }
440  if (cfg.isMember("max_rms_cut")) {
441  double val = cfg["max_rms_cut"].asDouble();
442  dump_cfg("maxrms", chans, val);
443  for (int ch : chans) {
444  //m_db.at(ch).max_rms_cut = val;
445  //dbget(ch).max_rms_cut = val;
446  get_ci(ch).max_rms_cut = val;
447  }
448  }
449  if (cfg.isMember("pad_window_front")) {
450  int val = cfg["pad_window_front"].asDouble();
451  dump_cfg("padfront", chans, val);
452  for (int ch : chans) {
453  //m_db.at(ch).pad_window_front = val;
454  //dbget(ch).pad_window_front = val;
456  }
457  }
458  if (cfg.isMember("pad_window_back")) {
459  int val = cfg["pad_window_back"].asDouble();
460  dump_cfg("padback", chans, val);
461  for (int ch : chans) {
462  //m_db.at(ch).pad_window_back = val;
463  //dbget(ch).pad_window_back = val;
464  get_ci(ch).pad_window_back = val;
465  }
466  }
467 
468  if (cfg.isMember("decon_limit")) {
469  float val = cfg["decon_limit"].asDouble();
470  dump_cfg("deconlimit", chans, val);
471  for (int ch : chans) {
472  //m_db.at(ch).decon_limit = val;
473  //dbget(ch).decon_limit = val;
474  get_ci(ch).decon_limit = val;
475  }
476  }
477 
478  if (cfg.isMember("decon_lf_cutoff")) {
479  float val = cfg["decon_lf_cutoff"].asDouble();
480  dump_cfg("deconlfcutoff", chans, val);
481  for (int ch : chans) {
482  //m_db.at(ch).decon_limit = val;
483  //dbget(ch).decon_limit = val;
484  get_ci(ch).decon_lf_cutoff = val;
485  }
486  }
487 
488  if (cfg.isMember("decon_limit1")) {
489  float val = cfg["decon_limit1"].asDouble();
490  dump_cfg("deconlimit1", chans, val);
491  for (int ch : chans) {
492  //m_db.at(ch).decon_limit1 = val;
493  //dbget(ch).decon_limit1 = val;
494  get_ci(ch).decon_limit1 = val;
495  }
496  }
497  if (cfg.isMember("adc_limit")) {
498  float val = cfg["adc_limit"].asDouble();
499  dump_cfg("adclimit", chans, val);
500  for (int ch : chans) {
501  //m_db.at(ch).adc_limit = val;
502  //dbget(ch).adc_limit = val;
503  get_ci(ch).adc_limit = val;
504  }
505  }
506  if (cfg.isMember("protection_factor")) {
507  float val = cfg["protection_factor"].asDouble();
508  dump_cfg("protectionfactor", chans, val);
509  for (int ch : chans) {
511  }
512  }
513  if (cfg.isMember("min_adc_limit")) {
514  float val = cfg["min_adc_limit"].asDouble();
515  dump_cfg("minadclimit", chans, val);
516  for (int ch : chans) {
517  //m_db.at(ch).adc_limit = val;
518  //dbget(ch).adc_limit = val;
519  get_ci(ch).min_adc_limit = val;
520  }
521  }
522  if (cfg.isMember("roi_min_max_ratio")) {
523  float val = cfg["roi_min_max_ratio"].asDouble();
524  dump_cfg("roiminmaxratio", chans, val);
525  for (int ch : chans) {
527  }
528  }
529 
530  {
531  auto jfilt = cfg["rcrc"];
532  if (!jfilt.isNull()) {
533  if (cfg.isMember("rc_layers")){
534  m_rc_layers = cfg["rc_layers"].asInt();
535  }
536  // std::cerr << "rc_layers = " << m_rc_layers << std::endl;
537  auto val = parse_rcrc(jfilt, m_rc_layers);
538  dump_cfg("rcrc", chans, Waveform::sum(*val));
539  for (int ch : chans) {
540  //m_db.at(ch).rcrc = val;
541  //dbget(ch).rcrc = val;
542  get_ci(ch).rcrc = val;
543  }
544  }
545  }
546  {
547  auto jfilt = cfg["reconfig"];
548  if (!jfilt.isNull()) {
549  auto val = parse_reconfig(jfilt);
550  dump_cfg("reconfig", chans, Waveform::sum(*val));
551  for (int ch : chans) {
552  //m_db.at(ch).config = val;
553  //dbget(ch).config = val;
554  get_ci(ch).config = val;
555  // fill in misconfgured channels
556  //std::cout <<" miscfg_channels fill: "<< ch <<"\n"
557  if(!jfilt.empty()) m_miscfg_channels.push_back(ch);
558  }
559  }
560  }
561  {
562  auto jfilt = cfg["freqmasks"];
563  if (!jfilt.isNull()) {
564  auto val = parse_freqmasks(jfilt);
565  dump_cfg("freqmasks", chans, Waveform::sum(*val));
566  // std::cerr << jfilt << std::endl;
567  for (int ch : chans) {
568  //m_db.at(ch).noise = val;
569  //dbget(ch).noise = val;
570  get_ci(ch).noise = val;
571  }
572  }
573  }
574  {
575  auto jfilt = cfg["response"];
576  if (!jfilt.isNull()) {
577  auto val = parse_response(jfilt);
578  dump_cfg("response", chans, Waveform::sum(*val));
579  for (int ch : chans) {
580  //m_db.at(ch).response = val;
581  //dbget(ch).response = val;
582  get_ci(ch).response = val;
583  }
584  }
585  }
586 
587 }
shared_filter_t parse_rcrc(Json::Value jrcrc, int nrc)
std::vector< int > parse_channels(const Json::Value &jchannels)
cfg
Definition: dbjson.py:29
double parse_gain(Json::Value jreconfig)
void dump_cfg(const std::string &name, std::vector< int > chans, Type val)
shared_filter_t parse_reconfig(Json::Value jreconfig)
Val sum(const Sequence< Val > &seq)
Return sum of all entries in sequence.
Definition: Waveform.h:178
shared_filter_t parse_response(Json::Value jreconfig)
shared_filter_t parse_freqmasks(Json::Value jfm)

Member Data Documentation

Log::logptr_t WireCell::SigProc::OmniChannelNoiseDB::log
private

Definition at line 182 of file OmniChannelNoiseDB.h.

IAnodePlane::pointer WireCell::SigProc::OmniChannelNoiseDB::m_anode
private

Definition at line 103 of file OmniChannelNoiseDB.h.

channel_group_t WireCell::SigProc::OmniChannelNoiseDB::m_bad_channels
private

Definition at line 152 of file OmniChannelNoiseDB.h.

std::vector< channel_group_t > WireCell::SigProc::OmniChannelNoiseDB::m_channel_groups
private

Definition at line 151 of file OmniChannelNoiseDB.h.

std::unordered_map<int, ChannelInfo> WireCell::SigProc::OmniChannelNoiseDB::m_db
private

Definition at line 136 of file OmniChannelNoiseDB.h.

IFieldResponse::pointer WireCell::SigProc::OmniChannelNoiseDB::m_fr
private

Definition at line 104 of file OmniChannelNoiseDB.h.

channel_group_t WireCell::SigProc::OmniChannelNoiseDB::m_miscfg_channels
private

Definition at line 153 of file OmniChannelNoiseDB.h.

int WireCell::SigProc::OmniChannelNoiseDB::m_nsamples
private

Definition at line 102 of file OmniChannelNoiseDB.h.

int WireCell::SigProc::OmniChannelNoiseDB::m_rc_layers
private

Definition at line 105 of file OmniChannelNoiseDB.h.

std::unordered_map<int, shared_filter_t> WireCell::SigProc::OmniChannelNoiseDB::m_rcrc_cache
private

Definition at line 174 of file OmniChannelNoiseDB.h.

std::unordered_map<int, shared_filter_t> WireCell::SigProc::OmniChannelNoiseDB::m_reconfig_cache
private

Definition at line 176 of file OmniChannelNoiseDB.h.

std::unordered_map<int, shared_filter_t> WireCell::SigProc::OmniChannelNoiseDB::m_response_cache
private

Definition at line 180 of file OmniChannelNoiseDB.h.

double WireCell::SigProc::OmniChannelNoiseDB::m_tick
private

Definition at line 101 of file OmniChannelNoiseDB.h.

std::unordered_map<int, shared_filter_t> WireCell::SigProc::OmniChannelNoiseDB::m_waveform_cache
private

Definition at line 178 of file OmniChannelNoiseDB.h.


The documentation for this class was generated from the following files: