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