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

#include <SimpleChannelNoiseDB.h>

Inheritance diagram for WireCell::SigProc::SimpleChannelNoiseDB:
WireCell::IChannelNoiseDatabase WireCell::IComponent< IChannelNoiseDatabase > WireCell::Interface

Public Types

typedef std::tuple< double, int, int > mask_t
 
typedef std::vector< mask_tmultimask_t
 
- 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 Member Functions

 SimpleChannelNoiseDB (double tick=0.5 *units::us, int nsamples=9600)
 
virtual ~SimpleChannelNoiseDB ()
 
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 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 double min_rms_cut (int channel) const
 
virtual double max_rms_cut (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...
 
void set_sampling (double tick=0.5 *units::us, int nsamples=9600)
 
void set_nominal_baseline (const std::vector< int > &channels, double baseline)
 Set nominal baseline in units of ADC (eg uB is -2048 for U/V, -400 for W) More...
 
void set_gains_shapings (const std::vector< int > &channels, double from_gain_mVfC=7.8, double to_gain_mVfC=14.0, double from_shaping=1.0 *units::us, double to_shaping=2.0 *units::us)
 
void set_response_offset (const std::vector< int > &channels, double offset)
 Set a response offset for the given set of channels. More...
 
void set_pad_window_front (const std::vector< int > &channels, int pad_f)
 
void set_pad_window_back (const std::vector< int > &channels, int pad_b)
 
void set_coherent_nf_decon_limit (const std::vector< int > &channels, float decon_limit)
 
void set_coherent_nf_decon_lf_cutoff (const std::vector< int > &channels, float decon_lf_cutoff)
 
void set_coherent_nf_decon_limit1 (const std::vector< int > &channels, float decon_limit)
 
void set_coherent_nf_adc_limit (const std::vector< int > &channels, float adc_limit)
 
void set_coherent_nf_protection_factor (const std::vector< int > &channels, float protection_factor)
 
void set_coherent_nf_min_adc_limit (const std::vector< int > &channels, float min_adc_limit)
 
void set_coherent_nf_roi_min_max_ratio (const std::vector< int > &channels, float roi_min_max_ratio)
 
void set_min_rms_cut (const std::vector< int > &channels, double min_rms)
 
void set_min_rms_cut_one (int channel, double min_rms)
 
void set_max_rms_cut (const std::vector< int > &channels, double max_rms)
 
void set_max_rms_cut_one (int channel, double max_rms)
 
void set_rcrc_constant (const std::vector< int > &channels, double rcrc=2000.0)
 
void set_response (const std::vector< int > &channels, const filter_t &spectrum)
 Set a detector response spectrum for the set of channels. More...
 
void set_filter (const std::vector< int > &channels, const multimask_t &mask)
 
void set_channel_groups (const std::vector< channel_group_t > &channel_groups)
 Set the channel groups. More...
 
void set_bad_channels (const channel_group_t &bc)
 Set "bad" channels. More...
 
- Public Member Functions inherited from WireCell::IChannelNoiseDatabase
virtual ~IChannelNoiseDatabase ()
 
virtual channel_group_t miscfg_channels () const
 Return channels which are considered a'priori "misconfigured". More...
 
- Public Member Functions inherited from WireCell::IComponent< IChannelNoiseDatabase >
virtual ~IComponent ()
 
- Public Member Functions inherited from WireCell::Interface
virtual ~Interface ()
 

Private Types

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

Private Member Functions

int chind (int ch) const
 
const IChannelNoiseDatabase::filter_tget_filter (int channel, const filter_vector_t &fv) const
 

Private Attributes

double m_tick
 
int m_nsamples
 
double m_default_baseline
 
double m_default_gain
 
double m_default_offset
 
double m_default_min_rms
 
double m_default_max_rms
 
int m_default_pad_f
 
int m_default_pad_b
 
float m_default_decon_limit
 
float m_default_decon_lf_cutoff
 
float m_default_adc_limit
 
float m_default_decon_limit1
 
float m_default_protection_factor
 
float m_default_min_adc_limit
 
float m_default_roi_min_max_ratio
 
std::vector< double > m_baseline
 
std::vector< double > m_gain
 
std::vector< double > m_offset
 
std::vector< double > m_min_rms
 
std::vector< double > m_max_rms
 
std::vector< int > m_pad_f
 
std::vector< int > m_pad_b
 
std::vector< float > m_decon_limit
 
std::vector< float > m_decon_lf_cutoff
 
std::vector< float > m_adc_limit
 
std::vector< float > m_decon_limit1
 
std::vector< float > m_protection_factor
 
std::vector< float > m_min_adc_limit
 
std::vector< float > m_roi_min_max_ratio
 
filter_vector_t m_rcrc
 
filter_vector_t m_config
 
filter_vector_t m_masks
 
filter_vector_t m_response
 
shared_filter_t m_default_filter
 
shared_filter_t m_default_response
 
std::unordered_map< int, int > m_ch2ind
 
std::vector< channel_group_tm_channel_groups
 
channel_group_t m_bad_channels
 

Detailed Description

Definition at line 17 of file SimpleChannelNoiseDB.h.

Member Typedef Documentation

Definition at line 145 of file SimpleChannelNoiseDB.h.

typedef std::tuple<double, int, int> WireCell::SigProc::SimpleChannelNoiseDB::mask_t

Set a constant scaling to a band covering the given frequency bins (inclusively) for the given channels. Frequency bin "i" is from i*f to (i+1)*f where f is 1.0/(nsamples*tick). The largest meaningful frequency bin is nsamples/2. The frequency band is inclusive of both min and max frequency bins. Note, it's up to caller to appropriately segment multiple masks across multiple channels. For any given channel, last call to this method wins.

Definition at line 119 of file SimpleChannelNoiseDB.h.

Definition at line 120 of file SimpleChannelNoiseDB.h.

Definition at line 144 of file SimpleChannelNoiseDB.h.

Constructor & Destructor Documentation

SimpleChannelNoiseDB::SimpleChannelNoiseDB ( double  tick = 0.5*units::us,
int  nsamples = 9600 
)

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

Definition at line 15 of file SimpleChannelNoiseDB.cxx.

16  : m_tick(-1)
17  , m_nsamples(-1)
18  , m_default_baseline(0.0)
19  , m_default_gain(1.0)
20  , m_default_offset(0.0)
21  , m_default_min_rms(0.5)
22  , m_default_max_rms(10)
23  , m_default_pad_f(0)
24  , m_default_pad_b(0)
25  , m_default_decon_limit(0.02)
27  , m_default_adc_limit(15.0)
32 {
33  set_sampling(tick, nsamples);
34 }
const double tick
void set_sampling(double tick=0.5 *units::us, int nsamples=9600)
SimpleChannelNoiseDB::~SimpleChannelNoiseDB ( )
virtual

Definition at line 35 of file SimpleChannelNoiseDB.cxx.

36 {
37 }

Member Function Documentation

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

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

Reimplemented from WireCell::IChannelNoiseDatabase.

Definition at line 55 of file SimpleChannelNoiseDB.h.

55  {
56  return m_bad_channels;
57  }
int SimpleChannelNoiseDB::chind ( int  ch) const
private

Definition at line 506 of file SimpleChannelNoiseDB.cxx.

507 {
508  auto it = m_ch2ind.find(ch);
509  if (it == m_ch2ind.end()) {
510  int ind = m_ch2ind.size();
511  m_ch2ind[ch] = ind;
512  return ind;
513  }
514  return it->second;
515 }
std::unordered_map< int, int > m_ch2ind
virtual std::vector<channel_group_t> WireCell::SigProc::SimpleChannelNoiseDB::coherent_channels ( ) const
inlinevirtual

Return channel grouping for coherent noise subtraction.

Implements WireCell::IChannelNoiseDatabase.

Definition at line 52 of file SimpleChannelNoiseDB.h.

52  {
53  return m_channel_groups;
54  }
std::vector< channel_group_t > m_channel_groups
float SimpleChannelNoiseDB::coherent_nf_adc_limit ( int  channel) const
virtual

Implements WireCell::IChannelNoiseDatabase.

Definition at line 136 of file SimpleChannelNoiseDB.cxx.

137 {
138  const int ind = chind(channel);
139  if (0 <= ind && ind < (int)m_adc_limit.size()) {
140  return m_adc_limit[ind];
141  }
142  return m_default_adc_limit;
143 }
float SimpleChannelNoiseDB::coherent_nf_decon_lf_cutoff ( int  channel) const
virtual

Implements WireCell::IChannelNoiseDatabase.

Definition at line 118 of file SimpleChannelNoiseDB.cxx.

119 {
120  const int ind = chind(channel);
121  if (0 <= ind && ind < (int)m_decon_lf_cutoff.size()) {
122  return m_decon_lf_cutoff[ind];
123  }
125 }
float SimpleChannelNoiseDB::coherent_nf_decon_limit ( int  channel) const
virtual

Implements WireCell::IChannelNoiseDatabase.

Definition at line 109 of file SimpleChannelNoiseDB.cxx.

110 {
111  const int ind = chind(channel);
112  if (0 <= ind && ind < (int)m_decon_limit.size()) {
113  return m_decon_limit[ind];
114  }
115  return m_default_decon_limit;
116 }
float SimpleChannelNoiseDB::coherent_nf_decon_limit1 ( int  channel) const
virtual

Implements WireCell::IChannelNoiseDatabase.

Definition at line 127 of file SimpleChannelNoiseDB.cxx.

128 {
129  const int ind = chind(channel);
130  if (0 <= ind && ind < (int)m_decon_limit1.size()) {
131  return m_decon_limit1[ind];
132  }
133  return m_default_decon_limit1;
134 }
float SimpleChannelNoiseDB::coherent_nf_min_adc_limit ( int  channel) const
virtual

Implements WireCell::IChannelNoiseDatabase.

Definition at line 154 of file SimpleChannelNoiseDB.cxx.

155 {
156  const int ind = chind(channel);
157  if (0 <= ind && ind < (int)m_min_adc_limit.size()) {
158  return m_min_adc_limit[ind];
159  }
161 }
float SimpleChannelNoiseDB::coherent_nf_protection_factor ( int  channel) const
virtual

Implements WireCell::IChannelNoiseDatabase.

Definition at line 145 of file SimpleChannelNoiseDB.cxx.

146 {
147  const int ind = chind(channel);
148  if (0 <= ind && ind < (int)m_protection_factor.size()) {
149  return m_protection_factor[ind];
150  }
152 }
float SimpleChannelNoiseDB::coherent_nf_roi_min_max_ratio ( int  channel) const
virtual

Implements WireCell::IChannelNoiseDatabase.

Definition at line 164 of file SimpleChannelNoiseDB.cxx.

165 {
166  const int ind = chind(channel);
167  if (0 <= ind && ind < (int)m_roi_min_max_ratio.size()) {
168  return m_roi_min_max_ratio[ind];
169  }
171 }
const IChannelNoiseDatabase::filter_t & SimpleChannelNoiseDB::config ( int  channel) const
virtual

Return the filter to correct any wrongly configured channels.

Implements WireCell::IChannelNoiseDatabase.

Definition at line 197 of file SimpleChannelNoiseDB.cxx.

198 {
199  return get_filter(channel, m_config);
200 }
const IChannelNoiseDatabase::filter_t & get_filter(int channel, const filter_vector_t &fv) const
double SimpleChannelNoiseDB::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 50 of file SimpleChannelNoiseDB.cxx.

51 {
52  const int ind = chind(channel);
53  if (0 <= ind && ind < (int)m_gain.size()) {
54  return m_gain[ind];
55  }
56  return m_default_gain;
57 }
const IChannelNoiseDatabase::filter_t & SimpleChannelNoiseDB::get_filter ( int  channel,
const filter_vector_t fv 
) const
private

Definition at line 174 of file SimpleChannelNoiseDB.cxx.

175 {
176  const int ind = chind(channel);
177  //std::cerr << "ch=" << channel << " ind=" << ind << " " << fv.size() << std::endl;
178  if (0 <= ind && ind < (int)fv.size()) {
179  const shared_filter_t sf = fv[ind];
180  if (sf == nullptr) {
181  return *(m_default_filter.get());
182  }
183 
184  const filter_t* filtp = sf.get();
185  return *filtp;
186  }
187  const filter_t* filtp = m_default_filter.get();
188  //std::cerr << "Filter: "<< (void*)filtp << std::endl;
189  return *filtp;
190 }
WireCell::Waveform::compseq_t filter_t
The data type for all frequency-space, multiplicative filters.
std::shared_ptr< filter_t > shared_filter_t
double SimpleChannelNoiseDB::max_rms_cut ( int  channel) const
virtual

Implements WireCell::IChannelNoiseDatabase.

Definition at line 78 of file SimpleChannelNoiseDB.cxx.

79 {
80  const int ind = chind(channel);
81  if (0 <= ind && ind < (int)m_max_rms.size()) {
82  return m_max_rms[ind];
83  }
84  return m_default_max_rms;
85 }
double SimpleChannelNoiseDB::min_rms_cut ( int  channel) const
virtual

Implements WireCell::IChannelNoiseDatabase.

Definition at line 69 of file SimpleChannelNoiseDB.cxx.

70 {
71  const int ind = chind(channel);
72  if (0 <= ind && ind < (int)m_min_rms.size()) {
73  return m_min_rms[ind];
74  }
75  return m_default_min_rms;
76 }
const IChannelNoiseDatabase::filter_t & SimpleChannelNoiseDB::noise ( int  channel) const
virtual

Return the filter to attenuate noise.

Implements WireCell::IChannelNoiseDatabase.

Definition at line 202 of file SimpleChannelNoiseDB.cxx.

203 {
204  return get_filter(channel, m_masks);
205 }
const IChannelNoiseDatabase::filter_t & get_filter(int channel, const filter_vector_t &fv) const
double SimpleChannelNoiseDB::nominal_baseline ( int  channel) const
virtual

Return a nominal baseline correction (additive offset)

Implements WireCell::IChannelNoiseDatabase.

Definition at line 41 of file SimpleChannelNoiseDB.cxx.

42 {
43  const int ind = chind(channel);
44  if (0 <= ind && ind < (int)m_baseline.size()) {
45  return m_baseline[ind];
46  }
47  return m_default_baseline;
48 }
int SimpleChannelNoiseDB::pad_window_back ( int  channel) const
virtual

Implements WireCell::IChannelNoiseDatabase.

Definition at line 99 of file SimpleChannelNoiseDB.cxx.

100 {
101  const int ind = chind(channel);
102  if (0 <= ind && ind < (int)m_pad_b.size()) {
103  return m_pad_b[ind];
104  }
105  return m_default_pad_b;
106 
107 }
int SimpleChannelNoiseDB::pad_window_front ( int  channel) const
virtual

Implements WireCell::IChannelNoiseDatabase.

Definition at line 89 of file SimpleChannelNoiseDB.cxx.

90 {
91  const int ind = chind(channel);
92  if (0 <= ind && ind < (int)m_pad_f.size()) {
93  return m_pad_f[ind];
94  }
95  return m_default_pad_f;
96 
97 }
const IChannelNoiseDatabase::filter_t & SimpleChannelNoiseDB::rcrc ( int  channel) const
virtual

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

Implements WireCell::IChannelNoiseDatabase.

Definition at line 192 of file SimpleChannelNoiseDB.cxx.

193 {
194  return get_filter(channel, m_rcrc);
195 }
const IChannelNoiseDatabase::filter_t & get_filter(int channel, const filter_vector_t &fv) const
const IChannelNoiseDatabase::filter_t & SimpleChannelNoiseDB::response ( int  channel) const
virtual

A nominal detector response spectrum for a given channel.

Implements WireCell::IChannelNoiseDatabase.

Definition at line 207 of file SimpleChannelNoiseDB.cxx.

208 {
209  return get_filter(channel, m_response);
210 }
const IChannelNoiseDatabase::filter_t & get_filter(int channel, const filter_vector_t &fv) const
double SimpleChannelNoiseDB::response_offset ( int  channel) const
virtual

Return a time offset associated with the response().

Implements WireCell::IChannelNoiseDatabase.

Definition at line 59 of file SimpleChannelNoiseDB.cxx.

60 {
61  const int ind = chind(channel);
62  if (0 <= ind && ind < (int)m_offset.size()) {
63  return m_offset[ind];
64  }
65  return m_default_offset;
66 
67 }
virtual double WireCell::SigProc::SimpleChannelNoiseDB::sample_time ( ) const
inlinevirtual

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 27 of file SimpleChannelNoiseDB.h.

void SimpleChannelNoiseDB::set_bad_channels ( const channel_group_t bc)

Set "bad" channels.

Definition at line 500 of file SimpleChannelNoiseDB.cxx.

501 {
502  //std::cerr << "SimpleChannelNoiseDB:: bad channels: " << bc.size() << std::endl;
503  m_bad_channels = bc;
504 }
void SimpleChannelNoiseDB::set_channel_groups ( const std::vector< channel_group_t > &  channel_groups)

Set the channel groups.

Definition at line 493 of file SimpleChannelNoiseDB.cxx.

494 {
495  //std::cerr << "SimpleChannelNoiseDB: channel groups: " << channel_groups.size() << " X " << channel_groups[0].size() << std::endl;
496  m_channel_groups = channel_groups;
497 }
std::vector< channel_group_t > m_channel_groups
void SimpleChannelNoiseDB::set_coherent_nf_adc_limit ( const std::vector< int > &  channels,
float  adc_limit 
)

Definition at line 433 of file SimpleChannelNoiseDB.cxx.

434 {
435  //std::cerr << "SimpleChannelNoiseDB: set pad window back on " << channels.size() << " channels: " << pad_b << std::endl;
436  for (auto ch : channels) {
437  int ind = chind(ch);
438  set_one(ind, adc_limit, m_adc_limit, m_default_adc_limit);
439  }
440 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_coherent_nf_decon_lf_cutoff ( const std::vector< int > &  channels,
float  decon_lf_cutoff 
)

Definition at line 414 of file SimpleChannelNoiseDB.cxx.

415 {
416  //std::cerr << "SimpleChannelNoiseDB: set pad window back on " << channels.size() << " channels: " << pad_b << std::endl;
417  for (auto ch : channels) {
418  int ind = chind(ch);
419  set_one(ind, decon_lf_cutoff, m_decon_lf_cutoff, m_default_decon_lf_cutoff);
420  }
421 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_coherent_nf_decon_limit ( const std::vector< int > &  channels,
float  decon_limit 
)

Definition at line 405 of file SimpleChannelNoiseDB.cxx.

406 {
407  //std::cerr << "SimpleChannelNoiseDB: set pad window back on " << channels.size() << " channels: " << pad_b << std::endl;
408  for (auto ch : channels) {
409  int ind = chind(ch);
410  set_one(ind, decon_limit, m_decon_limit, m_default_decon_limit);
411  }
412 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_coherent_nf_decon_limit1 ( const std::vector< int > &  channels,
float  decon_limit 
)

Definition at line 424 of file SimpleChannelNoiseDB.cxx.

425 {
426  //std::cerr << "SimpleChannelNoiseDB: set pad window back on " << channels.size() << " channels: " << pad_b << std::endl;
427  for (auto ch : channels) {
428  int ind = chind(ch);
429  set_one(ind, decon_limit1, m_decon_limit1, m_default_decon_limit1);
430  }
431 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_coherent_nf_min_adc_limit ( const std::vector< int > &  channels,
float  min_adc_limit 
)

Definition at line 451 of file SimpleChannelNoiseDB.cxx.

452 {
453  //std::cerr << "SimpleChannelNoiseDB: set pad window back on " << channels.size() << " channels: " << pad_b << std::endl;
454  for (auto ch : channels) {
455  int ind = chind(ch);
456  set_one(ind, min_adc_limit, m_min_adc_limit, m_default_min_adc_limit);
457  }
458 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_coherent_nf_protection_factor ( const std::vector< int > &  channels,
float  protection_factor 
)

Definition at line 442 of file SimpleChannelNoiseDB.cxx.

443 {
444  //std::cerr << "SimpleChannelNoiseDB: set pad window back on " << channels.size() << " channels: " << pad_b << std::endl;
445  for (auto ch : channels) {
446  int ind = chind(ch);
447  set_one(ind, protection_factor, m_protection_factor, m_default_protection_factor);
448  }
449 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_coherent_nf_roi_min_max_ratio ( const std::vector< int > &  channels,
float  roi_min_max_ratio 
)

Definition at line 460 of file SimpleChannelNoiseDB.cxx.

461 {
462  //std::cerr << "SimpleChannelNoiseDB: set pad window back on " << channels.size() << " channels: " << pad_b << std::endl;
463  for (auto ch : channels) {
464  int ind = chind(ch);
465  set_one(ind, roi_min_max_ratio, m_roi_min_max_ratio, m_default_roi_min_max_ratio);
466  }
467 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_filter ( const std::vector< int > &  channels,
const multimask_t mask 
)

Definition at line 469 of file SimpleChannelNoiseDB.cxx.

470 {
471  Waveform::compseq_t spectrum;
472  spectrum.resize(m_nsamples,std::complex<float>(1,0));
473 
474  for (auto m : masks) {
475  for (int ind=get<1>(m); ind <= get<2>(m); ++ind) {
476  //filt->assign(ind, get<0>(m));
477  spectrum.at(ind) = get<0>(m);
478  }
479  //std::cerr << "set freqmasks: " << get<1>(m) << " " << get<2>(m) << " " << get<0>(m) << " " << spectrum.at(0) << " " << spectrum.at(169) << " " << spectrum.at(170)<< std::endl;
480  }
481  auto filt = std::make_shared<filter_t>(spectrum);
482 
483 
484  for (auto ch : channels) {
485  set_one(chind(ch), filt, m_masks, m_default_filter);
486  }
487 
488 }
static const double m
Definition: Units.h:79
void set_one(int ind, T val, std::vector< T > &vec, T def)
Sequence< complex_t > compseq_t
A complex-valued sequence, eg for discrete spectrum powers.
Definition: Waveform.h:34
void SimpleChannelNoiseDB::set_gains_shapings ( const std::vector< int > &  channels,
double  from_gain_mVfC = 7.8,
double  to_gain_mVfC = 14.0,
double  from_shaping = 1.0*units::us,
double  to_shaping = 2.0*units::us 
)

Set gain/shaping corrections for cnofig_correction. Gains are assumed to be in mV/fC. Shaping times should be in the system of units. Defaults are microboone (but you need to give channels).

Definition at line 295 of file SimpleChannelNoiseDB.cxx.

298 {
299  const double gain_ratio = to_gain/from_gain;
300  // std::cerr << "SimpleChannelNoiseDB: set gain/shaping on " << channels.size() << " chans to: "
301  // << "g=" << from_gain << "->" << to_gain << ", "
302  // << "s=" << from_shaping << "->" << to_shaping << ", "
303  // << "rat=" << gain_ratio
304  // << "m_tick=" << m_tick/units::us << " us"
305  // << "\n";
306 
307 
308  Response::ColdElec from_ce(from_gain, from_shaping);
309  Response::ColdElec to_ce(to_gain, to_shaping);
310  // auto to_sig = to_ce.generate(WireCell::Binning(m_nsamples, 0, m_nsamples*m_tick));
311  // auto from_sig = from_ce.generate(WireCell::Binning(m_nsamples, 0, m_nsamples*m_tick));
312  auto to_sig = to_ce.generate(WireCell::Waveform::Domain(0, m_nsamples*m_tick), m_nsamples);
313  auto from_sig = from_ce.generate(WireCell::Waveform::Domain(0, m_nsamples*m_tick), m_nsamples);
314 
315  auto to_filt = Waveform::dft(to_sig);
316  auto from_filt = Waveform::dft(from_sig);
317 
318  // auto from_filt_sum = Waveform::sum(from_filt);
319  // auto to_filt_sum = Waveform::sum(to_filt);
320 
321  Waveform::shrink(to_filt, from_filt); // divide
322  auto filt = std::make_shared<filter_t>(to_filt);
323 
324  //std::cout << filt->at(0) << " " << filt->at(1) << std::endl;
325  // std::cerr << "SimpleChannelNoiseDB: "
326  // << " from_sig sum=" << Waveform::sum(from_sig)
327  // << " to_sig sum=" << Waveform::sum(to_sig)
328  // << " from_filt sum=" << from_filt_sum
329  // << " to_filt sum=" << to_filt_sum
330  // << " rat_filt sum=" << Waveform::sum(to_filt)
331  // << std::endl;
332 
333 
334  for (auto ch : channels) {
335  int ind = chind(ch);
337  set_one(ind, gain_ratio, m_gain, m_default_gain);
338  }
339 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
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
void SimpleChannelNoiseDB::set_max_rms_cut ( const std::vector< int > &  channels,
double  max_rms 
)

Definition at line 370 of file SimpleChannelNoiseDB.cxx.

371 {
372  //std::cerr << "SimpleChannelNoiseDB: set max rms cut on "<<channels.size()<<":[" << channels.front() << "," << channels.back() << "] to: " << max_rms << std::endl;
373  for (auto ch : channels) {
374  int ind = chind(ch);
375  set_one(ind, max_rms, m_max_rms, m_default_max_rms);
376  }
377 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_max_rms_cut_one ( int  channel,
double  max_rms 
)

Definition at line 379 of file SimpleChannelNoiseDB.cxx.

380 {
381  //std::cerr << "SimpleChannelNoiseDB: set max rms cut on " << ch << " to: " << max_rms << std::endl;
382  int ind = chind(ch);
383  set_one(ind, max_rms, m_max_rms, m_default_max_rms);
384 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_min_rms_cut ( const std::vector< int > &  channels,
double  min_rms 
)

Definition at line 352 of file SimpleChannelNoiseDB.cxx.

353 {
354  //std::cerr << "SimpleChannelNoiseDB: set min rms cut on "<<channels.size()<<":[" << channels.front() << "," << channels.back() << "] to: " << min_rms << std::endl;
355  for (auto ch : channels) {
356  int ind = chind(ch);
357  set_one(ind, min_rms, m_min_rms, m_default_min_rms);
358  }
359 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_min_rms_cut_one ( int  channel,
double  min_rms 
)

Definition at line 361 of file SimpleChannelNoiseDB.cxx.

362 {
363  //std::cerr << "SimpleChannelNoiseDB: set min rms cut on " << ch << " to: " << min_rms << std::endl;
364  int ind = chind(ch);
365  set_one(ind, min_rms, m_min_rms, m_default_min_rms);
366 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_nominal_baseline ( const std::vector< int > &  channels,
double  baseline 
)

Set nominal baseline in units of ADC (eg uB is -2048 for U/V, -400 for W)

Definition at line 245 of file SimpleChannelNoiseDB.cxx.

246 {
247  //std::cerr << "SimpleChannelNoiseDB: set baseline to " << channels.size() << " chans: " << baseline << std::endl;
248  for (auto ch : channels) {
249  set_one(chind(ch), baseline, m_baseline, m_default_baseline);
250  }
251 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_pad_window_back ( const std::vector< int > &  channels,
int  pad_b 
)

Definition at line 396 of file SimpleChannelNoiseDB.cxx.

397 {
398  //std::cerr << "SimpleChannelNoiseDB: set pad window back on " << channels.size() << " channels: " << pad_b << std::endl;
399  for (auto ch : channels) {
400  int ind = chind(ch);
401  set_one(ind, pad_b, m_pad_b, m_default_pad_b);
402  }
403 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_pad_window_front ( const std::vector< int > &  channels,
int  pad_f 
)

Definition at line 387 of file SimpleChannelNoiseDB.cxx.

388 {
389  //std::cerr << "SimpleChannelNoiseDB: set pad window front on " << channels.size() << " channels: " << pad_f << std::endl;
390  for (auto ch : channels) {
391  int ind = chind(ch);
392  set_one(ind, pad_f, m_pad_f, m_default_pad_f);
393  }
394 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_rcrc_constant ( const std::vector< int > &  channels,
double  rcrc = 2000.0 
)

Set the RC+RC time constant in the system of units for the digitization sample time ("tick"). Default is for microboone.

Definition at line 252 of file SimpleChannelNoiseDB.cxx.

253 {
254  Response::SimpleRC rcres(rcrc,m_tick);
255  //auto signal = rcres.generate(WireCell::Waveform::Domain(0, m_nsamples*m_tick), m_nsamples);
256  // auto signal = rcres.generate(WireCell::Binning(m_nsamples, 0, m_nsamples*m_tick));
257  auto signal = rcres.generate(WireCell::Waveform::Domain(0, m_nsamples*m_tick), m_nsamples);
258 
259  Waveform::compseq_t spectrum = Waveform::dft(signal);
260 
261  //std::cout << rcrc << " " << m_tick << " " << m_nsamples << " " << signal.front() << " " << signal.at(1) << " " << signal.at(2) << std::endl;
262 
263  // get the square of it because there are two RC filters
264  Waveform::compseq_t spectrum2 = spectrum;
265  Waveform::scale(spectrum2,spectrum);
266  // for (auto it : spectrum){
267  // float real_part = it.real();
268  // float imag_part = it.imag();
269  // std::complex<float> temp(real_part*real_part-imag_part*imag_part,2*real_part*imag_part);
270  // spectrum2.push_back(temp);
271  // }
272 
273  // std::cerr << "SimpleChannelNoiseDB:: get rcrc as: " << rcrc
274  // << " sum=" << Waveform::sum(spectrum2)
275  // << std::endl;
276 
277  auto filt = std::make_shared<filter_t>(spectrum2);
278 
279  for (auto ch : channels) {
281  }
282 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
compseq_t dft(realseq_t seq)
Definition: Waveform.cxx:141
std::pair< double, double > Domain
Definition: Waveform.h:75
void scale(Sequence< Val > &seq, Val scalar)
Scale (multiply) sequence values by scalar.
Definition: Waveform.h:146
virtual const filter_t & rcrc(int channel) const
Return the filter for the RC+RC coupling response function.
Sequence< complex_t > compseq_t
A complex-valued sequence, eg for discrete spectrum powers.
Definition: Waveform.h:34
void SimpleChannelNoiseDB::set_response ( const std::vector< int > &  channels,
const filter_t spectrum 
)

Set a detector response spectrum for the set of channels.

Definition at line 284 of file SimpleChannelNoiseDB.cxx.

285 {
286  //std::cerr << "SimpleChannelNoiseDB: set respnose on " << channels.size() << " chans with: " << spectrum.size() << " samples\n";
287 
288  auto filt = std::make_shared<filter_t>(spectrum);
289  for (auto ch : channels) {
291  }
292 
293 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_response_offset ( const std::vector< int > &  channels,
double  offset 
)

Set a response offset for the given set of channels.

Definition at line 341 of file SimpleChannelNoiseDB.cxx.

342 {
343  //std::cerr << "SimpleChannelNoiseDB: set response offset " << channels.size() << " chans to: " << offset << std::endl;
344  for (auto ch : channels) {
345  int ind = chind(ch);
346  set_one(ind, offset, m_offset, m_default_offset);
347  }
348 }
void set_one(int ind, T val, std::vector< T > &vec, T def)
void SimpleChannelNoiseDB::set_sampling ( double  tick = 0.5*units::us,
int  nsamples = 9600 
)

Set the size and number of samples of a channel's waveform, default is for microboone.

Warning: calling this will reset any settings for gains+shaping and rcrc as they depend on knowing the sampling.

Definition at line 213 of file SimpleChannelNoiseDB.cxx.

214 {
215 
216  if (m_nsamples == nsamples && tick == m_tick) {
217  //std::cerr << "Sampling unchanged: " << nsamples << " @ " << m_tick/units::ms << " ms" << std::endl;
218  return;
219  }
220  m_nsamples = nsamples;
221  m_tick = tick;
222 
223  m_rcrc.clear();
224  m_config.clear();
225  m_response.clear();
226 
227  Waveform::compseq_t spectrum;
228  spectrum.resize(nsamples,std::complex<float>(1,0));
229  m_default_filter = std::make_shared<filter_t>(spectrum);
231  m_default_response = std::make_shared<filter_t>(empty);
232 }
const double tick
Sequence< complex_t > compseq_t
A complex-valued sequence, eg for discrete spectrum powers.
Definition: Waveform.h:34
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:92

Member Data Documentation

std::vector<float> WireCell::SigProc::SimpleChannelNoiseDB::m_adc_limit
private

Definition at line 141 of file SimpleChannelNoiseDB.h.

channel_group_t WireCell::SigProc::SimpleChannelNoiseDB::m_bad_channels
private

Definition at line 156 of file SimpleChannelNoiseDB.h.

std::vector<double> WireCell::SigProc::SimpleChannelNoiseDB::m_baseline
private

Definition at line 139 of file SimpleChannelNoiseDB.h.

std::unordered_map<int,int> WireCell::SigProc::SimpleChannelNoiseDB::m_ch2ind
mutableprivate

Definition at line 150 of file SimpleChannelNoiseDB.h.

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

Definition at line 155 of file SimpleChannelNoiseDB.h.

filter_vector_t WireCell::SigProc::SimpleChannelNoiseDB::m_config
private

Definition at line 146 of file SimpleChannelNoiseDB.h.

std::vector<float> WireCell::SigProc::SimpleChannelNoiseDB::m_decon_lf_cutoff
private

Definition at line 141 of file SimpleChannelNoiseDB.h.

std::vector<float> WireCell::SigProc::SimpleChannelNoiseDB::m_decon_limit
private

Definition at line 141 of file SimpleChannelNoiseDB.h.

std::vector<float> WireCell::SigProc::SimpleChannelNoiseDB::m_decon_limit1
private

Definition at line 141 of file SimpleChannelNoiseDB.h.

float WireCell::SigProc::SimpleChannelNoiseDB::m_default_adc_limit
private

Definition at line 137 of file SimpleChannelNoiseDB.h.

double WireCell::SigProc::SimpleChannelNoiseDB::m_default_baseline
private

Definition at line 134 of file SimpleChannelNoiseDB.h.

float WireCell::SigProc::SimpleChannelNoiseDB::m_default_decon_lf_cutoff
private

Definition at line 137 of file SimpleChannelNoiseDB.h.

float WireCell::SigProc::SimpleChannelNoiseDB::m_default_decon_limit
private

Definition at line 137 of file SimpleChannelNoiseDB.h.

float WireCell::SigProc::SimpleChannelNoiseDB::m_default_decon_limit1
private

Definition at line 137 of file SimpleChannelNoiseDB.h.

shared_filter_t WireCell::SigProc::SimpleChannelNoiseDB::m_default_filter
private

Definition at line 147 of file SimpleChannelNoiseDB.h.

double WireCell::SigProc::SimpleChannelNoiseDB::m_default_gain
private

Definition at line 134 of file SimpleChannelNoiseDB.h.

double WireCell::SigProc::SimpleChannelNoiseDB::m_default_max_rms
private

Definition at line 135 of file SimpleChannelNoiseDB.h.

float WireCell::SigProc::SimpleChannelNoiseDB::m_default_min_adc_limit
private

Definition at line 137 of file SimpleChannelNoiseDB.h.

double WireCell::SigProc::SimpleChannelNoiseDB::m_default_min_rms
private

Definition at line 135 of file SimpleChannelNoiseDB.h.

double WireCell::SigProc::SimpleChannelNoiseDB::m_default_offset
private

Definition at line 134 of file SimpleChannelNoiseDB.h.

int WireCell::SigProc::SimpleChannelNoiseDB::m_default_pad_b
private

Definition at line 136 of file SimpleChannelNoiseDB.h.

int WireCell::SigProc::SimpleChannelNoiseDB::m_default_pad_f
private

Definition at line 136 of file SimpleChannelNoiseDB.h.

float WireCell::SigProc::SimpleChannelNoiseDB::m_default_protection_factor
private

Definition at line 137 of file SimpleChannelNoiseDB.h.

shared_filter_t WireCell::SigProc::SimpleChannelNoiseDB::m_default_response
private

Definition at line 148 of file SimpleChannelNoiseDB.h.

float WireCell::SigProc::SimpleChannelNoiseDB::m_default_roi_min_max_ratio
private

Definition at line 137 of file SimpleChannelNoiseDB.h.

std::vector<double> WireCell::SigProc::SimpleChannelNoiseDB::m_gain
private

Definition at line 139 of file SimpleChannelNoiseDB.h.

filter_vector_t WireCell::SigProc::SimpleChannelNoiseDB::m_masks
private

Definition at line 146 of file SimpleChannelNoiseDB.h.

std::vector<double> WireCell::SigProc::SimpleChannelNoiseDB::m_max_rms
private

Definition at line 139 of file SimpleChannelNoiseDB.h.

std::vector<float> WireCell::SigProc::SimpleChannelNoiseDB::m_min_adc_limit
private

Definition at line 141 of file SimpleChannelNoiseDB.h.

std::vector<double> WireCell::SigProc::SimpleChannelNoiseDB::m_min_rms
private

Definition at line 139 of file SimpleChannelNoiseDB.h.

int WireCell::SigProc::SimpleChannelNoiseDB::m_nsamples
private

Definition at line 132 of file SimpleChannelNoiseDB.h.

std::vector<double> WireCell::SigProc::SimpleChannelNoiseDB::m_offset
private

Definition at line 139 of file SimpleChannelNoiseDB.h.

std::vector<int> WireCell::SigProc::SimpleChannelNoiseDB::m_pad_b
private

Definition at line 140 of file SimpleChannelNoiseDB.h.

std::vector<int> WireCell::SigProc::SimpleChannelNoiseDB::m_pad_f
private

Definition at line 140 of file SimpleChannelNoiseDB.h.

std::vector<float> WireCell::SigProc::SimpleChannelNoiseDB::m_protection_factor
private

Definition at line 141 of file SimpleChannelNoiseDB.h.

filter_vector_t WireCell::SigProc::SimpleChannelNoiseDB::m_rcrc
private

Definition at line 146 of file SimpleChannelNoiseDB.h.

filter_vector_t WireCell::SigProc::SimpleChannelNoiseDB::m_response
private

Definition at line 146 of file SimpleChannelNoiseDB.h.

std::vector<float> WireCell::SigProc::SimpleChannelNoiseDB::m_roi_min_max_ratio
private

Definition at line 141 of file SimpleChannelNoiseDB.h.

double WireCell::SigProc::SimpleChannelNoiseDB::m_tick
private

Definition at line 131 of file SimpleChannelNoiseDB.h.


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