EmpiricalNoiseModel.h
Go to the documentation of this file.
1 /**
2  A noise model based on empirically measured noise spectra.
3 
4  It requires configuration file holding a list of dictionary which
5  provide association between wire length and the noise spectrum.
6 
7  TBD: document JSON file format for providing spectra and any other parameters.
8 
9 */
10 
11 
12 #ifndef WIRECELLGEN_EMPERICALNOISEMODEL
13 #define WIRECELLGEN_EMPERICALNOISEMODEL
14 
19 
20 #include "WireCellUtil/Units.h"
21 #include "WireCellUtil/Waveform.h"
22 #include "WireCellUtil/Logging.h"
23 
24 #include <string>
25 #include <vector>
26 #include <unordered_map>
27 
28 namespace WireCell {
29  namespace Gen {
30 
32  public:
33  EmpiricalNoiseModel(const std::string& spectra_file = "",
34  const int nsamples = 10000, // assuming 10k samples
35  const double period = 0.5*units::us,
36  const double wire_length_scale = 1.0*units::cm,
37  /* const double time_scale = 1.0*units::ns, */
38  /* const double gain_scale = 1.0*units::volt/units::eplus, */
39  /* const double freq_scale = 1.0*units::megahertz, */
40  const std::string anode_tn = "AnodePlane",
41  const std::string chanstat_tn = "StaticChannelStatus");
42 
43  virtual ~EmpiricalNoiseModel();
44 
45  /// IChannelSpectrum
46  virtual const amplitude_t& operator()(int chid) const;
47 
48  // get constant term
49  virtual const std::vector<float>& freq() const;
50  // get json file gain
51  virtual const double gain(int chid) const;
52  // get json file shaping time
53  virtual const double shaping_time(int chid) const;
54 
55 
56  /// IConfigurable
57  virtual void configure(const WireCell::Configuration& config);
59 
60 
61  // Local methods
62 
63  // fixme: this should be factored out into wire-cell-util.
64  struct NoiseSpectrum {
65  int plane; // plane identifier number
66  int nsamples; // number of samples used in preparing spectrum
67  double period; // sample period [time] used in preparing spectrum
68  double gain; // amplifier gain [voltage/charge]
69  double shaping; // amplifier shaping time [time]
70  double wirelen; // total length of wire conductor [length]
71  double constant; // amplifier independent constant noise component [voltage/frequency]
72  std::vector<float> freqs; // the frequencies at which the spectrum is sampled
73  std::vector<float> amps; // the amplitude [voltage/frequency] of the spectrum.
74  };
75 
76  // Resample a NoiseSpectrum to match what the model was
77  // configured to provide. This method modifies in place.
78  void resample(NoiseSpectrum& spectrum) const;
79 
80  // generate the default electronics response function at 1 mV/fC gain
81  void gen_elec_resp_default();
82 
83  // Return a new amplitude which is the interpolation
84  // between those given in the spectra file.
85  amplitude_t interpolate(int plane, double wire_length) const;
86 
87  int get_nsamples(){return m_nsamples;};
88 
89  private:
92 
96  double m_period, m_wlres;
97  // double m_tres, m_gres, m_fres;
99 
100 
101  std::map<int, std::vector<NoiseSpectrum*> > m_spectral_data;
102 
103  // cache amplitudes to the nearest integral distance.
104  mutable std::unordered_map<int, int> m_chid_to_intlen;
105 
106  typedef std::unordered_map<int, amplitude_t> len_amp_cache_t;
107  mutable std::vector<len_amp_cache_t> m_amp_cache;
108 
109  // need to convert the electronics response in here ...
111  mutable std::unordered_map<int, Waveform::realseq_t> m_elec_resp_cache;
113 
115  };
116 
117  }
118 }
119 
120 
121 #endif
virtual const double gain(int chid) const
std::vector< len_amp_cache_t > m_amp_cache
void resample(NoiseSpectrum &spectrum) const
Sequence< real_t > realseq_t
Definition: Waveform.h:31
virtual const std::vector< float > & freq() const
std::unordered_map< int, amplitude_t > len_amp_cache_t
std::vector< float > amplitude_t
std::string string
Definition: nybbler.cc:12
virtual const amplitude_t & operator()(int chid) const
IChannelSpectrum.
virtual const double shaping_time(int chid) const
EmpiricalNoiseModel(const std::string &spectra_file="", const int nsamples=10000, const double period=0.5 *units::us, const double wire_length_scale=1.0 *units::cm, const std::string anode_tn="AnodePlane", const std::string chanstat_tn="StaticChannelStatus")
virtual void configure(const WireCell::Configuration &config)
IConfigurable.
static Config * config
Definition: config.cpp:1054
std::shared_ptr< Interface > pointer
Definition: Interface.h:16
virtual WireCell::Configuration default_configuration() const
Optional, override to return a hard-coded default configuration.
static const double cm
Definition: Units.h:59
std::shared_ptr< spdlog::logger > logptr_t
Definition: Logging.h:24
Definition: Main.h:22
amplitude_t interpolate(int plane, double wire_length) const
Json::Value Configuration
Definition: Configuration.h:50
std::map< int, std::vector< NoiseSpectrum * > > m_spectral_data
static const double us
Definition: Units.h:105
std::unordered_map< int, Waveform::realseq_t > m_elec_resp_cache
std::unordered_map< int, int > m_chid_to_intlen