LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SignalShaping.h
Go to the documentation of this file.
1 
58 #ifndef SIGNALSHAPING_H
59 #define SIGNALSHAPING_H
60 
61 #include "TComplex.h"
62 #include <vector>
63 
66 
67 namespace util {
68 
69  class SignalShaping {
70  public:
71  // Constructor, destructor.
72  SignalShaping();
73  virtual ~SignalShaping();
74 
75  // Accessors.
76  const std::vector<double>& Response() const { return fResponse; }
77  const std::vector<double>& Response_save() const { return fResponse_save; }
78  const std::vector<TComplex>& ConvKernel() const { return fConvKernel; }
79  const std::vector<TComplex>& Filter() const { return fFilter; }
80  const std::vector<TComplex>& DeconvKernel() const { return fDeconvKernel; }
81  /* const int GetTimeOffset() const {return fTimeOffset;} */
82 
83  // Signal shaping methods.
84 
85  // Convolute a time series with convolution kernel.
86  template <class T>
87  void Convolute(std::vector<T>& func) const;
88 
89  // Convolute a time series with deconvolution kernel.
90  template <class T>
91  void Deconvolute(std::vector<T>& func) const;
92 
93  // Configuration methods.
94 
95  // Only reset deconvolution
96  //void ResetDecon();
97  // Reset this class to default-constructed state.
98  void Reset();
99 
101  {
102  fResponse_save.clear();
104  }
105  void set_normflag(bool flag) { fNorm = flag; }
106 
107  // Add a time domain response function.
108  // Updates overall response function and convolution kernel.
109  void AddResponseFunction(const std::vector<double>& resp, bool ResetResponse = false);
110 
111  /* //X. Qian, set time offset */
112  /* void SetTimeOffset(const int time){fTimeOffset = time;} */
113 
114  // Shift response function in time.
115  // Updates overall response function and convolution kernel.
116  void ShiftResponseTime(double ticks);
117  void SetPeakResponseTime(double tick);
118 
119  // Add a filter function.
120  void AddFilterFunction(const std::vector<TComplex>& filt);
121 
122  //Add DeconvKernel Polarity switch to decide how to normalize
123  //deconvoluted signal w.r.t. RawDigits. If +1 then normalize
124  //to Max ADC, if -1 to Min ADC
125  void SetDeconvKernelPolarity(int pol);
126 
127  // Test and lock the current response function.
128  // Does not lock filter configuration.
129  void LockResponse() const;
130 
131  // Calculate deconvolution kernel using current convolution kernel
132  // and filter function.
133  // Fully locks configuration.
134  void CalculateDeconvKernel() const;
135 
136  private:
137  // Attributes.
138  // unused double fMinConvKernelFrac; ///< minimum value of convKernel/peak for deconvolution
139 
140  // Lock flags.
141  mutable bool fResponseLocked;
142  mutable bool fFilterLocked;
143 
144  // Overall response.
145  std::vector<double> fResponse;
146  std::vector<double> fResponse_save;
147 
148  // Convolution kernel (fourier transform of response function).
149  std::vector<TComplex> fConvKernel;
150 
151  // Overall filter function.
152  std::vector<TComplex> fFilter;
153 
154  // Deconvolution kernel (= fFilter / fConvKernel).
155  mutable std::vector<TComplex> fDeconvKernel;
156 
157  // Deconvolution Kernel Polarity Flag
158  // Set to +1 if deconv signal should be deconv to + ADC count
159  // Set to -1 if one wants to normalize to - ADC count
161 
162  // Xin added */
163  bool fNorm;
164  };
165 
166 }
167 
168 //----------------------------------------------------------------------
169 // Convolute a time series with current response.
170 template <class T>
171 inline void util::SignalShaping::Convolute(std::vector<T>& func) const
172 {
173  // Make sure response configuration is locked.
175 
177 
178  // Make sure that time series has the correct size.
179  if (int const n = func.size(); n != fft->FFTSize())
180  throw cet::exception("SignalShaping") << "Bad time series size = " << n << "\n";
181 
182  fft->Convolute(func, const_cast<std::vector<TComplex>&>(fConvKernel));
183 }
184 
185 //----------------------------------------------------------------------
186 // Convolute a time series with deconvolution kernel.
187 template <class T>
188 inline void util::SignalShaping::Deconvolute(std::vector<T>& func) const
189 {
190  // Make sure deconvolution kernel is configured.
192 
194 
195  // Make sure that time series has the correct size.
196  if (int const n = func.size(); n != fft->FFTSize())
197  throw cet::exception("SignalShaping") << "Bad time series size = " << n << "\n";
198 
199  fft->Convolute(func, fDeconvKernel);
200 }
201 
202 #endif
void set_normflag(bool flag)
const std::vector< double > & Response_save() const
Definition: SignalShaping.h:77
void Deconvolute(std::vector< T > &func) const
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:26
std::vector< TComplex > fConvKernel
const std::vector< double > & Response() const
Definition: SignalShaping.h:76
void AddResponseFunction(const std::vector< double > &resp, bool ResetResponse=false)
void LockResponse() const
std::vector< TComplex > fFilter
tick ticks
Alias for common language habits.
Definition: electronics.h:76
void Convolute(std::vector< T > &func) const
int FFTSize() const
Definition: LArFFT.h:66
void CalculateDeconvKernel() const
void SetDeconvKernelPolarity(int pol)
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:73
void Convolute(std::vector< T > &input, std::vector< T > &respFunc)
Definition: LArFFT.h:170
const std::vector< TComplex > & DeconvKernel() const
Definition: SignalShaping.h:80
void ShiftResponseTime(double ticks)
std::vector< TComplex > fDeconvKernel
const std::vector< TComplex > & Filter() const
Definition: SignalShaping.h:79
void SetPeakResponseTime(double tick)
std::vector< double > fResponse
std::vector< double > fResponse_save
Char_t n[5]
const std::vector< TComplex > & ConvKernel() const
Definition: SignalShaping.h:78
void AddFilterFunction(const std::vector< TComplex > &filt)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33