LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SignalShaper.h
Go to the documentation of this file.
1 #ifndef SIGNALSHAPER_H
2 #define SIGNALSHAPER_H
3 
4 #include <complex>
5 #include <vector>
6 
10 
11 namespace util {
12 
13  class SignalShaper {
14  public:
15  // Constructor, destructor.
16  SignalShaper(int fftsize, std::string fftopt);
17  virtual ~SignalShaper();
18 
19  // Accessors.
20  const std::vector<double>& Response() const { return fResponse; }
21  const std::vector<double>& Response_save() const { return fResponse_save; }
22  const std::vector<std::complex<double>>& ConvKernel() const { return fConvKernel; }
23  const std::vector<std::complex<double>>& Filter() const { return fFilter; }
24  const std::vector<std::complex<double>>& DeconvKernel() const { return fDeconvKernel; }
25 
26  // Signal shaping methods.
27 
28  // Convolute a time series with convolution kernel.
29  template <class T>
30  void Convolute(std::vector<T>& func) const;
31 
32  // Convolute a time series with deconvolution kernel.
33  template <class T>
34  void Deconvolute(std::vector<T>& func) const;
35 
36  // Configuration methods.
37 
38  // Reset this class to default-constructed state.
39  void Reset();
40 
42  {
43  fResponse_save.clear();
45  }
46  void set_normflag(bool flag) { fNorm = flag; }
47 
48  // Add a time domain response function.
49  // Updates overall response function and convolution kernel.
50  void AddResponseFunction(const std::vector<double>& resp, bool ResetResponse = false);
51 
52  // Shift response function in time.
53  // Updates overall response function and convolution kernel.
54  void ShiftResponseTime(double ticks);
55  void SetPeakResponseTime(double tick);
56 
57  // Add a filter function.
58  void AddFilterFunction(const std::vector<std::complex<double>>& filt);
59 
60  //Add DeconvKernel Polarity switch to decide how to normalize
61  //deconvoluted signal w.r.t. RawDigits. If +1 then normalize
62  //to Max ADC, if -1 to Min ADC
63  void SetDeconvKernelPolarity(int pol);
64 
65  // Test and lock the current response function.
66  // Does not lock filter configuration.
67  void LockResponse() const;
68 
69  // Calculate deconvolution kernel using current convolution kernel
70  // and filter function.
71  // Fully locks configuration.
72  void CalculateDeconvKernel() const;
73 
74  private:
75  // Attributes.
76  // unused double fMinConvKernelFrac; ///< minimum value of convKernel/peak for deconvolution
77 
78  // Lock flags.
79  mutable bool fResponseLocked;
80  mutable bool fFilterLocked;
81 
82  // Overall response.
83  std::vector<double> fResponse;
84  std::vector<double> fResponse_save;
85 
86  // Convolution kernel (fourier transform of response function).
87  std::vector<std::complex<double>> fConvKernel;
88 
89  // Overall filter function.
90  std::vector<std::complex<double>> fFilter;
91 
92  // Deconvolution kernel (= fFilter / fConvKernel).
93  mutable std::vector<std::complex<double>> fDeconvKernel;
94 
95  // Deconvolution Kernel Polarity Flag
96  // Set to +1 if deconv signal should be deconv to + ADC count
97  // Set to -1 if one wants to normalize to - ADC count
99 
100  // Xin added */
101  bool fNorm;
102 
103  int fFFTSize;
104  const void* fPlan;
105  const void* rPlan;
106  std::unique_ptr<util::LArFFTWPlan> fFFTPlan;
107  std::unique_ptr<util::LArFFTW> fFFT;
108  };
109 
110 }
111 
112 #endif
void CalculateDeconvKernel() const
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:26
void AddFilterFunction(const std::vector< std::complex< double >> &filt)
void ShiftResponseTime(double ticks)
std::unique_ptr< util::LArFFTWPlan > fFFTPlan
Definition: SignalShaper.h:106
const std::vector< double > & Response() const
Definition: SignalShaper.h:20
const void * fPlan
Definition: SignalShaper.h:104
std::vector< double > fResponse_save
Definition: SignalShaper.h:84
virtual ~SignalShaper()
const std::vector< std::complex< double > > & ConvKernel() const
Definition: SignalShaper.h:22
void SetPeakResponseTime(double tick)
tick ticks
Alias for common language habits.
Definition: electronics.h:76
void AddResponseFunction(const std::vector< double > &resp, bool ResetResponse=false)
const void * rPlan
Definition: SignalShaper.h:105
void LockResponse() const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
const std::vector< double > & Response_save() const
Definition: SignalShaper.h:21
std::vector< double > fResponse
Definition: SignalShaper.h:83
std::unique_ptr< util::LArFFTW > fFFT
Definition: SignalShaper.h:107
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:73
void Deconvolute(std::vector< T > &func) const
std::vector< std::complex< double > > fConvKernel
Definition: SignalShaper.h:87
void set_normflag(bool flag)
Definition: SignalShaper.h:46
SignalShaper(int fftsize, std::string fftopt)
Definition: SignalShaper.cxx:8
const std::vector< std::complex< double > > & Filter() const
Definition: SignalShaper.h:23
const std::vector< std::complex< double > > & DeconvKernel() const
Definition: SignalShaper.h:24
std::vector< std::complex< double > > fDeconvKernel
Definition: SignalShaper.h:93
void SetDeconvKernelPolarity(int pol)
std::vector< std::complex< double > > fFilter
Definition: SignalShaper.h:90
void Convolute(std::vector< T > &func) const