SimpleChannelNoiseDB.h
Go to the documentation of this file.
1 #ifndef WIRECELLSIGPROC_SIMPLECHANNELNOISEDB
2 #define WIRECELLSIGPROC_SIMPLECHANNELNOISEDB
3 
5 
7 #include "WireCellUtil/Units.h"
8 
9 #include <vector>
10 #include <tuple>
11 #include <unordered_map>
12 #include <memory>
13 
14 namespace WireCell {
15  namespace SigProc {
16 
18  public:
19 
20  /// Create a simple channel noise DB for digitized waveforms
21  /// with the given size and number of samples. Default is for
22  /// microboone.
23  SimpleChannelNoiseDB(double tick=0.5*units::us, int nsamples=9600);
24  virtual ~SimpleChannelNoiseDB();
25 
26  // IChannelNoiseDatabase
27  virtual double sample_time() const { return m_tick; }
28 
29  virtual double nominal_baseline(int channel) const;
30  virtual double gain_correction(int channel) const;
31  virtual double response_offset(int channel) const;
32  virtual int pad_window_front(int channel) const;
33  virtual int pad_window_back(int channel) const;
34 
35  virtual float coherent_nf_decon_limit(int channel) const;
36  virtual float coherent_nf_decon_lf_cutoff(int channel) const;
37  virtual float coherent_nf_decon_limit1(int channel) const;
38  virtual float coherent_nf_adc_limit(int channel) const;
39  virtual float coherent_nf_protection_factor(int channel) const;
40  virtual float coherent_nf_min_adc_limit(int channel) const;
41  virtual float coherent_nf_roi_min_max_ratio(int channel) const;
42 
43  virtual double min_rms_cut(int channel) const;
44  virtual double max_rms_cut(int channel) const;
45 
46 
47  virtual const filter_t& rcrc(int channel) const;
48  virtual const filter_t& config(int channel) const;
49  virtual const filter_t& noise(int channel) const;
50  virtual const filter_t& response(int channel) const;
51 
52  virtual std::vector<channel_group_t> coherent_channels() const {
53  return m_channel_groups;
54  }
55  virtual channel_group_t bad_channels() const {
56  return m_bad_channels;
57  }
58 
59  // concrete helper methods
60 
61  /// Set the size and number of samples of a channel's
62  /// waveform, default is for microboone.
63  ///
64  /// Warning: calling this will reset any settings for
65  /// gains+shaping and rcrc as they depend on knowing the
66  /// sampling.
67  void set_sampling(double tick=0.5*units::us, int nsamples=9600);
68 
69  /// Set nominal baseline in units of ADC (eg uB is -2048 for U/V, -400 for W)
70  void set_nominal_baseline(const std::vector<int>& channels, double baseline);
71 
72  /// Set gain/shaping corrections for cnofig_correction. Gains
73  /// are assumed to be in mV/fC. Shaping times should be in
74  /// the system of units. Defaults are microboone (but you
75  /// need to give channels).
76  void set_gains_shapings(const std::vector<int>& channels,
77  double from_gain_mVfC=7.8, double to_gain_mVfC=14.0,
78  double from_shaping=1.0*units::us, double to_shaping=2.0*units::us);
79 
80 
81  /// Set a response offset for the given set of channels.
82  void set_response_offset(const std::vector<int>& channels, double offset);
83  void set_pad_window_front(const std::vector<int>& channels, int pad_f);
84  void set_pad_window_back(const std::vector<int>& channels, int pad_b);
85 
86  void set_coherent_nf_decon_limit(const std::vector<int>& channels, float decon_limit);
87  void set_coherent_nf_decon_lf_cutoff(const std::vector<int>& channels, float decon_lf_cutoff);
88  void set_coherent_nf_decon_limit1(const std::vector<int>& channels, float decon_limit);
89  void set_coherent_nf_adc_limit(const std::vector<int>& channels, float adc_limit);
90  void set_coherent_nf_protection_factor(const std::vector<int>& channels, float protection_factor);
91  void set_coherent_nf_min_adc_limit(const std::vector<int>& channels, float min_adc_limit);
92  void set_coherent_nf_roi_min_max_ratio(const std::vector<int>& channels, float roi_min_max_ratio);
93 
94  void set_min_rms_cut(const std::vector<int>& channels, double min_rms);
95  void set_min_rms_cut_one(int channel, double min_rms);
96  void set_max_rms_cut(const std::vector<int>& channels, double max_rms);
97  void set_max_rms_cut_one(int channel, double max_rms);
98 
99 
100 
101  /// Set the RC+RC time constant in the system of units for the
102  /// digitization sample time ("tick"). Default is for microboone.
103  void set_rcrc_constant(const std::vector<int>& channels, double rcrc=2000.0);
104 
105 
106  /// Set a detector response spectrum for the set of channels
107  void set_response(const std::vector<int>& channels, const filter_t& spectrum);
108 
109 
110  /// Set a constant scaling to a band covering the given
111  /// frequency bins (inclusively) for the given channels.
112  /// Frequency bin "i" is from i*f to (i+1)*f where f is
113  /// 1.0/(nsamples*tick). The largest meaningful frequency bin
114  /// is nsamples/2. The frequency band is *inclusive* of both
115  /// min and max frequency bins. Note, it's up to caller to
116  /// appropriately segment multiple masks across multiple
117  /// channels. For any given channel, last call to this method
118  /// wins.
119  typedef std::tuple<double, int, int> mask_t;
120  typedef std::vector<mask_t> multimask_t;
121  void set_filter(const std::vector<int>& channels, const multimask_t& mask);
122 
123  /// Set the channel groups
124  void set_channel_groups(const std::vector< channel_group_t >& channel_groups);
125 
126  /// Set "bad" channels.
127  void set_bad_channels(const channel_group_t& bc);
128 
129 
130  private:
131  double m_tick;
133 
138 
139  std::vector<double> m_baseline, m_gain, m_offset, m_min_rms, m_max_rms;
140  std::vector<int> m_pad_f, m_pad_b;
142 
143 
144  typedef std::shared_ptr<filter_t> shared_filter_t;
145  typedef std::vector<shared_filter_t> filter_vector_t;
146  filter_vector_t m_rcrc, m_config, m_masks, m_response;
147  shared_filter_t m_default_filter;
148  shared_filter_t m_default_response;
149 
150  mutable std::unordered_map<int,int> m_ch2ind;
151  int chind(int ch) const;
152 
153  const IChannelNoiseDatabase::filter_t& get_filter(int channel, const filter_vector_t& fv) const;
154 
155  std::vector< channel_group_t > m_channel_groups;
157  };
158  }
159 
160 }
161 
162 #endif
163 
164 // Local Variables:
165 // mode: c++
166 // c-basic-offset: 4
167 // End:
SimpleChannelNoiseDB(double tick=0.5 *units::us, int nsamples=9600)
void set_coherent_nf_decon_lf_cutoff(const std::vector< int > &channels, float decon_lf_cutoff)
void set_coherent_nf_decon_limit(const std::vector< int > &channels, float decon_limit)
virtual int pad_window_back(int channel) const
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_coherent_nf_protection_factor(const std::vector< int > &channels, float protection_factor)
void set_max_rms_cut(const std::vector< int > &channels, double max_rms)
virtual const filter_t & config(int channel) const
Return the filter to correct any wrongly configured channels.
void set_coherent_nf_min_adc_limit(const std::vector< int > &channels, float min_adc_limit)
virtual double min_rms_cut(int channel) const
virtual int pad_window_front(int channel) const
void set_coherent_nf_roi_min_max_ratio(const std::vector< int > &channels, float roi_min_max_ratio)
void set_max_rms_cut_one(int channel, double max_rms)
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)
void set_rcrc_constant(const std::vector< int > &channels, double rcrc=2000.0)
const double tick
void set_filter(const std::vector< int > &channels, const multimask_t &mask)
void set_min_rms_cut(const std::vector< int > &channels, double min_rms)
virtual float coherent_nf_roi_min_max_ratio(int channel) const
std::unordered_map< int, int > m_ch2ind
virtual channel_group_t bad_channels() const
Return channels which are considered a&#39;priori "bad".
virtual std::vector< channel_group_t > coherent_channels() const
Return channel grouping for coherent noise subtraction.
void set_pad_window_front(const std::vector< int > &channels, int pad_f)
virtual const filter_t & response(int channel) const
A nominal detector response spectrum for a given channel.
virtual float coherent_nf_adc_limit(int channel) const
void set_min_rms_cut_one(int channel, double min_rms)
void set_response_offset(const std::vector< int > &channels, double offset)
Set a response offset for the given set of channels.
virtual float coherent_nf_decon_limit1(int channel) const
void set_coherent_nf_decon_limit1(const std::vector< int > &channels, float decon_limit)
WireCell::Waveform::compseq_t filter_t
The data type for all frequency-space, multiplicative filters.
virtual double max_rms_cut(int channel) const
Definition: Main.h:22
virtual double response_offset(int channel) const
Return a time offset associated with the response().
virtual float coherent_nf_protection_factor(int channel) const
virtual float coherent_nf_min_adc_limit(int channel) const
void set_response(const std::vector< int > &channels, const filter_t &spectrum)
Set a detector response spectrum for the set of channels.
virtual const filter_t & noise(int channel) const
Return the filter to attenuate noise.
std::shared_ptr< filter_t > shared_filter_t
const IChannelNoiseDatabase::filter_t & get_filter(int channel, const filter_vector_t &fv) const
static const double us
Definition: Units.h:105
void set_channel_groups(const std::vector< channel_group_t > &channel_groups)
Set the channel groups.
virtual float coherent_nf_decon_limit(int channel) const
std::vector< shared_filter_t > filter_vector_t
virtual double sample_time() const
FIXME: how to handle state changes?
void set_pad_window_back(const std::vector< int > &channels, int pad_b)
std::vector< channel_group_t > m_channel_groups
virtual const filter_t & rcrc(int channel) const
Return the filter for the RC+RC coupling response function.
virtual float coherent_nf_decon_lf_cutoff(int channel) const
void set_coherent_nf_adc_limit(const std::vector< int > &channels, float adc_limit)
void set_bad_channels(const channel_group_t &bc)
Set "bad" channels.
void set_sampling(double tick=0.5 *units::us, int nsamples=9600)
virtual double nominal_baseline(int channel) const
Return a nominal baseline correction (additive offset)
virtual double gain_correction(int channel) const
std::tuple< double, int, int > mask_t